home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Libraries / DCLAP 4j / vibrant / vibutils.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-17  |  90.3 KB  |  4,044 lines  |  [TEXT/R*ch]

  1. /*   vibutils.c
  2. * ===========================================================================
  3. *
  4. *                            PUBLIC DOMAIN NOTICE
  5. *            National Center for Biotechnology Information (NCBI)
  6. *
  7. *  This software/database is a "United States Government Work" under the
  8. *  terms of the United States Copyright Act.  It was written as part of
  9. *  the author's official duties as a United States Government employee and
  10. *  thus cannot be copyrighted.  This software/database is freely available
  11. *  to the public for use. The National Library of Medicine and the U.S.
  12. *  Government do not place any restriction on its use or reproduction.
  13. *  We would, however, appreciate having the NCBI and the author cited in
  14. *  any work or product based on this material
  15. *
  16. *  Although all reasonable efforts have been taken to ensure the accuracy
  17. *  and reliability of the software and data, the NLM and the U.S.
  18. *  Government do not and cannot warrant the performance or results that
  19. *  may be obtained by using this software or data. The NLM and the U.S.
  20. *  Government disclaim all warranties, express or implied, including
  21. *  warranties of performance, merchantability or fitness for any particular
  22. *  purpose.
  23. *
  24. * ===========================================================================
  25. *
  26. * File Name:  vibutils.c
  27. *
  28. * Author:  Jonathan Kans
  29. *
  30. * Version Creation Date:   7/1/91
  31. *
  32. * $Revision: 2.44 $
  33. *
  34. * File Description: 
  35. *       Vibrant miscellaneous functions
  36. *
  37. * Modifications:  
  38. * --------------------------------------------------------------------------
  39. * Date     Name        Description of modification
  40. * -------  ----------  -----------------------------------------------------
  41. *
  42. *
  43. * ==========================================================================
  44. */
  45.  
  46. #include <vibtypes.h>
  47. #include <vibprocs.h>
  48. #include <vibincld.h>
  49. #include <ncbiport.h>
  50.  
  51. #ifdef WIN_MAC
  52. #include <Printing.h>
  53. #include <Processes.h>
  54. #include <GestaltEqu.h>
  55. /*#include <Strings.h> */
  56. #endif
  57.  
  58. #ifdef WIN_MSWIN
  59. #include <commdlg.h>
  60. #endif
  61.  
  62. #ifdef WIN_MOTIF
  63. #include <Xm/FileSB.h>
  64. #ifdef OS_UNIX
  65. #include <unistd.h>
  66. #endif
  67. #ifdef OS_VMS
  68. #endif
  69. #endif
  70.  
  71. #ifdef WIN_MAC
  72. Nlm_Int2     Nlm_nextIdNumber = 2;
  73. #endif
  74. #ifdef WIN_MSWIN
  75. Nlm_Int2     Nlm_nextIdNumber = 102;
  76. #endif
  77. #ifdef WIN_MOTIF
  78. Nlm_Int2     Nlm_nextIdNumber = 1;
  79. #endif
  80.  
  81. Nlm_PoinT    Nlm_globalMouse;
  82. Nlm_PoinT    Nlm_localMouse;
  83.  
  84. Nlm_Int2     Nlm_hScrollBarHeight;
  85. Nlm_Int2     Nlm_vScrollBarWidth;
  86.  
  87. Nlm_Int2     Nlm_dialogTextHeight;
  88. Nlm_Int2     Nlm_popupMenuHeight;
  89.  
  90. Nlm_Char     Nlm_currentKey = '\0';
  91.  
  92. Nlm_Boolean  Nlm_cmmdKey = FALSE;
  93. Nlm_Boolean  Nlm_ctrlKey = FALSE;
  94. Nlm_Boolean  Nlm_optKey = FALSE;
  95. Nlm_Boolean  Nlm_shftKey = FALSE;
  96. Nlm_Boolean  Nlm_dblClick = FALSE;
  97.  
  98. static Nlm_WindoW       postWindow = NULL;
  99. static Nlm_PrompT       postPrompt = NULL;
  100.  
  101. static Nlm_Boolean      errorBoxUp;
  102. static Nlm_Int2         errorBoxRsult;
  103.  
  104. static Nlm_GraphiC      recentGraphic = NULL;
  105. static Nlm_GraphicData  recentGraphicData;
  106.  
  107. static Nlm_BoX          recentBox = NULL;
  108. static Nlm_BoxData      recentBoxData;
  109.  
  110. #ifdef WIN_MAC
  111. static THPrint   prHdl = NULL;
  112. static TPPrPort  prPort = NULL;
  113. static Nlm_Int2  prerr;
  114. static Nlm_Char  fileTypes [32] = {0};
  115. #endif
  116.  
  117. #ifdef WIN_MSWIN
  118. static Nlm_Boolean   abortPrint;
  119. static HDC           hPr = NULL;
  120. static Nlm_Int2      prerr;
  121. static int           vibrant_disabled = 0;
  122. static int           disabled_count = 0;
  123. static PRINTDLG      pd;
  124. static OPENFILENAME  ofn;
  125. #endif
  126.  
  127. #ifdef WIN_MOTIF
  128. static Widget       fileDialog = NULL;
  129. static Nlm_Boolean  fileBoxUp;
  130. static Nlm_Boolean  fileBoxRsult;
  131. static Nlm_Char     filePath [256];
  132. #endif
  133.  
  134. extern Nlm_Uint4 Nlm_StrngLen (Nlm_CharPtr string)
  135.  
  136. {
  137.   Nlm_Uint4  len;
  138.  
  139.   len = 0;
  140.   if (string != NULL) {
  141.     while (*string != '\0') {
  142.       string++;
  143.       len++;
  144.     }
  145.   }
  146.   return len;
  147. }
  148.  
  149. extern void Nlm_StrngCat (Nlm_CharPtr dest, Nlm_CharPtr source, Nlm_sizeT maxsize)
  150.  
  151. {
  152.   Nlm_Uint4  count;
  153.   Nlm_Uint4  i;
  154.  
  155.   if (dest != NULL && source != NULL && maxsize > 0) {
  156.     count = Nlm_StrngLen (source);
  157.     i = Nlm_StrngLen (dest);
  158.     if (count + i >= maxsize) {
  159.       count = maxsize - i - 1;
  160.     }
  161.     dest += i;
  162.     while (count > 0) {
  163.       *dest = *source;
  164.       dest++;
  165.       source++;
  166.       count--;
  167.     }
  168.     *dest = '\0';
  169.   }
  170. }
  171.  
  172. extern void Nlm_StrngCpy (Nlm_CharPtr dest, Nlm_CharPtr source, Nlm_sizeT maxsize)
  173.  
  174. {
  175.   Nlm_Uint4  count;
  176.  
  177.   if (dest != NULL && maxsize > 0) {
  178.     count = Nlm_StrngLen (source);
  179.     if (count >= maxsize) {
  180.       count = maxsize - 1;
  181.     }
  182.     while (count > 0) {
  183.       *dest = *source;
  184.       dest++;
  185.       source++;
  186.       count--;
  187.     }
  188.     *dest = '\0';
  189.   }
  190. }
  191.  
  192. static Nlm_Boolean Nlm_InNumber (Nlm_Char ch)
  193.  
  194. {
  195.   return (Nlm_Boolean) (ch >= '0' && ch <= '9') ;
  196. }
  197.  
  198. static Nlm_Char Nlm_Cap (Nlm_Char ch, Nlm_Boolean caseCounts)
  199.  
  200. {
  201.   if (caseCounts) {
  202.     return ch;
  203.   } else if (ch >= 'a' && ch <= 'z') {
  204.     return (Nlm_Char) (ch - ' ');
  205.   } else {
  206.     return ch;
  207.   }
  208. }
  209.  
  210. extern Nlm_Boolean Nlm_StrngPos (Nlm_CharPtr str, Nlm_CharPtr sub,
  211.                                  Nlm_Uint4 start, Nlm_Boolean caseCounts,
  212.                                  Nlm_Uint4Ptr match)
  213.  
  214. {
  215.   Nlm_Char     ch1;
  216.   Nlm_Char     ch2;
  217.   Nlm_Uint4    count;
  218.   Nlm_Boolean  found;
  219.   Nlm_Uint4    i;
  220.   Nlm_Uint4    j;
  221.   Nlm_Uint4    len;
  222.   Nlm_Uint4    max;
  223.   Nlm_Uint4    sublen;
  224.  
  225.   found = FALSE;
  226.   if (str != NULL && sub != NULL) {
  227.     len = Nlm_StrngLen (str);
  228.     sublen = Nlm_StrngLen (sub);
  229.     if (len < sublen) {
  230.       sublen = len;
  231.     }
  232.     max = len - sublen;
  233.     i = start;
  234.     if (match != NULL) {
  235.       *match = 0;
  236.     }
  237.     if (start < len) {
  238.       do {
  239.         found = TRUE;
  240.         j = 0;
  241.         count = sublen;
  242.         while (found && count > 0) {
  243.           ch1 = Nlm_Cap (str [i + j], caseCounts);
  244.           ch2 = Nlm_Cap (sub [j], caseCounts);
  245.           if (ch1 != ch2) {
  246.             found = FALSE;
  247.           }
  248.           j++;
  249.           count--;
  250.         }
  251.         if (found && match != NULL) {
  252.           *match = i;
  253.         }
  254.         i++;
  255.       } while ((! found) && (i <= max));
  256.     }
  257.     else {
  258.       found = FALSE;
  259.     }
  260.   }
  261.   return found;
  262. }
  263.  
  264. extern void Nlm_StrngSeg (Nlm_CharPtr dest, Nlm_CharPtr source,
  265.                           Nlm_Uint4 start, Nlm_Uint4 length,
  266.                           Nlm_sizeT maxsize)
  267.  
  268. {
  269.   Nlm_Uint4  count;
  270.   Nlm_Uint4  len;
  271.  
  272.   if (dest != NULL && source != NULL && maxsize > 0) {
  273.     count = length;
  274.     len = Nlm_StrngLen (source);
  275.     if (start + length > len) {
  276.       count = len - start;
  277.     }
  278.     if (count >= maxsize) {
  279.       count = maxsize - 1;
  280.     }
  281.     source += start;
  282.     while (count > 0) {
  283.       *dest = *source;
  284.       dest++;
  285.       source++;
  286.       count--;
  287.     }
  288.     *dest = '\0';
  289.   }
  290. }
  291.  
  292. extern void Nlm_StrngRep (Nlm_CharPtr dest, Nlm_CharPtr source,
  293.                           Nlm_Uint4 start, Nlm_sizeT maxsize)
  294.  
  295. {
  296.   Nlm_Uint4  count;
  297.  
  298.   if (dest != NULL && source != NULL && maxsize > 0) {
  299.     count = Nlm_StrngLen (source);
  300.     if (count + start >= maxsize) {
  301.       count = maxsize - start - 1;
  302.     }
  303.     dest += start;
  304.     while (count > 0) {
  305.       *dest = *source;
  306.       dest++;
  307.       source++;
  308.       count--;
  309.     }
  310.   }
  311. }
  312.  
  313. extern Nlm_Boolean Nlm_StrngEql (Nlm_CharPtr str1, Nlm_CharPtr str2,
  314.                                  Nlm_Boolean caseCounts)
  315.  
  316. {
  317.   return (Nlm_Boolean) (Nlm_StrngCmp (str1, str2, caseCounts) == 0);
  318. }
  319.  
  320. extern Nlm_Int2 Nlm_StrngCmp (Nlm_CharPtr str1, Nlm_CharPtr str2,
  321.                               Nlm_Boolean caseCounts)
  322.  
  323. {
  324.   Nlm_Uint4  count;
  325.   Nlm_Uint4  i;
  326.   Nlm_Uint4  len1;
  327.   Nlm_Uint4  len2;
  328.   Nlm_Int2   rsult;
  329.  
  330.   rsult = 0;
  331.   if (str1 != NULL && str2 != NULL) {
  332.     len1 = Nlm_StrngLen (str1);
  333.     len2 = Nlm_StrngLen (str2);
  334.     if (len1 > len2) {
  335.       count = len2;
  336.     } else {
  337.       count = len1;
  338.     }
  339.     i = 0;
  340.     while (count > 0 && Nlm_Cap (str1 [i], caseCounts) == Nlm_Cap (str2 [i], caseCounts)) {
  341.       i++;
  342.       count--;
  343.     }
  344.     if (count > 0) {
  345.       if (Nlm_Cap (str1 [i], caseCounts) > Nlm_Cap (str2 [i], caseCounts)) {
  346.         rsult = 1;
  347.       } else {
  348.         rsult = -1;
  349.       }
  350.     } else {
  351.       if (len1 > len2) {
  352.         rsult = 1;
  353.       } else if (len1 < len2) {
  354.         rsult = -1;
  355.       } else {
  356.         rsult = 0;
  357.       }
  358.     }
  359.   }
  360.   return rsult;
  361. }
  362.  
  363. extern Nlm_Int2 Nlm_SymblCmp (Nlm_CharPtr str1, Nlm_CharPtr str2,
  364.                               Nlm_Boolean caseCounts)
  365.  
  366. {
  367.   Nlm_Boolean  cont;
  368.   Nlm_Boolean  done;
  369.   Nlm_Uint4    i;
  370.   Nlm_Uint4    j;
  371.   Nlm_Uint4    len1;
  372.   Nlm_Uint4    len2;
  373.   Nlm_Uint4    num1;
  374.   Nlm_Uint4    num2;
  375.   Nlm_Int2     rsult;
  376.  
  377.   rsult = 0;
  378.   if (str1 != NULL && str2 != NULL) {
  379.     done = FALSE;
  380.     len1 = Nlm_StrngLen (str1);
  381.     len2 = Nlm_StrngLen (str2);
  382.     i = 0;
  383.     j = 0;
  384.     cont = (Nlm_Boolean) (len1 > 0 && len2 > 0);
  385.     while (cont) {
  386.       if (Nlm_InNumber (str1 [i]) && Nlm_InNumber (str2 [j])) {
  387.         num1 = 0;
  388.         while (i < len1 && Nlm_InNumber (str1 [i]) && (num1 < 429496729)) {
  389.           num1 *= 10;
  390.           num1 += (str1 [i] - '0');
  391.           i++;
  392.         }
  393.         num2 = 0;
  394.         while (j < len2 && Nlm_InNumber (str2 [j]) && (num2 < 429496729)) {
  395.           num2 *= 10;
  396.           num2 += (str2 [j] - '0');
  397.           j++;
  398.         }
  399.         if (num1 > num2) {
  400.           rsult = 1;
  401.           done = TRUE;
  402.           cont = FALSE;
  403.         } else if (num1 < num2) {
  404.           rsult = -1;
  405.           done = TRUE;
  406.           cont = FALSE;
  407.         } else {
  408.           cont = (Nlm_Boolean) (i < len1 && j < len2);
  409.         }
  410.       } else if (Nlm_Cap (str1 [i], caseCounts) > Nlm_Cap (str2 [j], caseCounts)) {
  411.         rsult = 1;
  412.         done = TRUE;
  413.         cont = FALSE;
  414.       } else if (Nlm_Cap (str1 [i], caseCounts) < Nlm_Cap (str2 [j], caseCounts)) {
  415.         rsult = -1;
  416.         done = TRUE;
  417.         cont = FALSE;
  418.       } else {
  419.         i++;
  420.         j++;
  421.         cont = (Nlm_Boolean) (i < len1 && j < len2);
  422.       }
  423.     }
  424.     if (done) {
  425.     } else if (i < len1 && j == len2) {
  426.       rsult = 1;
  427.     } else if (i == len1 && j < len2) {
  428.       rsult = -1;
  429.     } else {
  430.       rsult = 0;
  431.     }
  432.   }
  433.   return rsult;
  434. }
  435.  
  436. extern Nlm_Handle Nlm_SetString (Nlm_Handle h, Nlm_CharPtr str)
  437.  
  438. {
  439.   Nlm_sizeT       len;
  440.   Nlm_CharPtr  pp;
  441.  
  442.   if (str != NULL) {
  443.     len = Nlm_StringLen (str);
  444.     if (len > 0) {
  445.       if (h != NULL) {
  446.         h = Nlm_HandMore (h, len + 1);
  447.       } else {
  448.         h = Nlm_HandNew (len + 1);
  449.       }
  450.     } else if (h != NULL) {
  451.       Nlm_HandFree (h);
  452.       h = NULL;
  453.     }
  454.   } else {
  455.     Nlm_HandFree (h);
  456.     h = NULL;
  457.   }
  458.   if (h != NULL) {
  459.     pp = (Nlm_CharPtr) Nlm_HandLock (h);
  460.     if (pp != NULL) {
  461.       Nlm_StringNCpy (pp, str, len + 1);
  462.     }
  463.     Nlm_HandUnlock (h);
  464.   }
  465.   return h;
  466. }
  467.  
  468. extern void Nlm_GetString (Nlm_Handle h, Nlm_CharPtr str, Nlm_sizeT maxsize)
  469.  
  470. {
  471.   Nlm_CharPtr  pp;
  472.  
  473.   if (str != NULL) {
  474.     if (h != NULL) {
  475.       pp = (Nlm_CharPtr) Nlm_HandLock (h);
  476.       if (pp != NULL) {
  477.         Nlm_StringNCpy (str, pp, maxsize);
  478.       }
  479.       Nlm_HandUnlock (h);
  480.     } else {
  481.       Nlm_StringNCpy (str, "", maxsize);
  482.     }
  483.   }
  484. }
  485.  
  486. static void Nlm_MssgErrorProc (Nlm_ButtoN b)
  487.  
  488. {
  489.   errorBoxUp = FALSE;
  490.   errorBoxRsult = ANS_NO;
  491. }
  492.  
  493. static void Nlm_MssgFatalProc (Nlm_ButtoN b)
  494.  
  495. {
  496.   errorBoxUp = FALSE;
  497.   errorBoxRsult = ANS_NO;
  498. }
  499.  
  500. static void Nlm_MssgNoProc (Nlm_ButtoN b)
  501.  
  502. {
  503.   errorBoxUp = FALSE;
  504.   errorBoxRsult = ANS_NO;
  505. }
  506.  
  507. static void Nlm_MssgYesProc (Nlm_ButtoN b)
  508.  
  509. {
  510.   errorBoxUp = FALSE;
  511.   errorBoxRsult = ANS_YES;
  512. }
  513.  
  514. static void Nlm_MssgOkayProc (Nlm_ButtoN b)
  515.  
  516. {
  517.   errorBoxUp = FALSE;
  518.   errorBoxRsult = ANS_OK;
  519. }
  520.  
  521. static void Nlm_MssgRetryProc (Nlm_ButtoN b)
  522.  
  523. {
  524.   errorBoxUp = FALSE;
  525.   errorBoxRsult = ANS_RETRY;
  526. }
  527.  
  528. static void Nlm_MssgAbortProc (Nlm_ButtoN b)
  529.  
  530. {
  531.   errorBoxUp = FALSE;
  532.   errorBoxRsult = ANS_ABORT;
  533. }
  534.  
  535. static void Nlm_MssgCancelProc (Nlm_ButtoN b)
  536.  
  537. {
  538.   errorBoxUp = FALSE;
  539.   errorBoxRsult = ANS_CANCEL;
  540. }
  541.  
  542. static void Nlm_MssgIgnoreProc (Nlm_ButtoN b)
  543.  
  544. {
  545.   errorBoxUp = FALSE;
  546.   errorBoxRsult = ANS_IGNORE;
  547. }
  548.  
  549. static void Nlm_ClosePostProc (Nlm_WindoW w)
  550.  
  551. {
  552.   Nlm_Hide (w);
  553. }
  554.  
  555. static MsgAnswer LIBCALLBACK Nlm_VibMessageHook (MsgKey key, ErrSev severity,
  556.                                                  const char * caption, const char * message)
  557.  
  558. {
  559.   Nlm_CharPtr  buf;
  560.   Nlm_Int2     answer;
  561.   Nlm_sizeT       len;
  562.   Nlm_Int2     rsult;
  563.   Nlm_WindoW   tempPort;
  564.   Nlm_Int2     wtype;
  565. #ifdef WIN_MAC
  566.   Nlm_ButtoN   b [3];
  567.   Nlm_Char     ch;
  568.   void         *data;
  569.   Nlm_Int2     delta;
  570.   Nlm_Boolean  fatal;
  571.   Nlm_GrouP    g;
  572.   Nlm_Int2     i;
  573.   Nlm_Int2     j;
  574.   Nlm_Int2     margin;
  575.   Nlm_Int2     maxWidth;
  576.   Nlm_PoinT    npt;
  577.   Nlm_Int2     percent;
  578.   Nlm_RecT     r;
  579.   Nlm_Int2     rgt;
  580.   Nlm_WindoW   w;
  581.   Nlm_Int2     width;
  582. #endif
  583. #ifdef WIN_MOTIF
  584.   Nlm_ButtoN   b [3];
  585.   Nlm_Char     ch;
  586.   void         *data;
  587.   Nlm_Int2     delta;
  588.   Nlm_Boolean  fatal;
  589.   Nlm_GrouP    g;
  590.   Nlm_Int2     i;
  591.   Nlm_Int2     j;
  592.   Nlm_Int2     margin;
  593.   Nlm_Int2     maxWidth;
  594.   Nlm_PoinT    npt;
  595.   Nlm_Int2     percent;
  596.   Nlm_RecT     r;
  597.   Nlm_Int2     rgt;
  598.   Nlm_WindoW   w;
  599.   Nlm_Int2     width;
  600. #endif
  601.  
  602.   rsult = 0;
  603.   len = MIN (Nlm_StringLen (message), (Nlm_sizeT) 4094);
  604.   buf = (Nlm_CharPtr) Nlm_MemNew (len + 2);
  605.   Nlm_StringNCpy (buf, message, len);
  606.   if (key == KEY_NONE && severity == SEV_INFO) {
  607.     tempPort = Nlm_CurrentWindow ();
  608.     if (postWindow == NULL) {
  609.       postWindow = Nlm_DocumentWindow (-50, -90, -20, -20, "Message",
  610.                                        Nlm_ClosePostProc, NULL);
  611.       postPrompt = Nlm_StaticPrompt (postWindow, "", 30 * Nlm_stdCharWidth,
  612.                                      Nlm_stdLineHeight, Nlm_systemFont, 'c');
  613.     }
  614.     if (postWindow != NULL && postPrompt != NULL) {
  615.       Nlm_SetTitle (postPrompt, buf);
  616.       if (! Nlm_Visible (postWindow)) {
  617.         Nlm_Show (postWindow);
  618.       }
  619.       Nlm_Select (postWindow);
  620.     }
  621.     Nlm_RestorePort (tempPort);
  622.     return (MsgAnswer) 0;
  623.   }
  624. #ifndef WIN_MSWIN
  625.   data = Nlm_GetAppProperty ("VibrantMessageWidthMax");
  626.   if (data != NULL) {
  627.     percent = (Nlm_Int2) data;
  628.     if (percent < 0) {
  629.       percent = 100;
  630.     }
  631.   } else {
  632.     percent = 100;
  633.   }
  634.   percent = MAX (percent, 25);
  635.   percent = MIN (percent, 95);
  636.   maxWidth = (Nlm_Int2) ((Nlm_Int4) (Nlm_screenRect.right - Nlm_screenRect.left) *
  637.               (Nlm_Int4) percent / (Nlm_Int4) 100) - 40;
  638.   maxWidth = MAX (maxWidth, 100);
  639. #endif
  640. #ifdef WIN_MAC
  641.   w = Nlm_ModalWindow (-50, -20, -20, -20, NULL);
  642.   g = Nlm_HiddenGroup (w, 0, 10, NULL);
  643.   Nlm_GetNextPosition (g, &npt);
  644.   npt.x += 6;
  645.   Nlm_SetNextPosition (g, npt);
  646.   i = 0;
  647.   while (Nlm_StringLen (buf + i) > 0) {
  648.     width = 0;
  649.     j = 0;
  650.     while (buf [i + j] == ' ') {
  651.       i++;
  652.     }
  653.     ch = buf [i + j];
  654.     width += Nlm_CharWidth (ch);
  655.     while (ch != '\0' && ch != '\n' && ch != '\r' && width <= maxWidth) {
  656.       j++;
  657.       ch = buf [i + j];
  658.       width += Nlm_CharWidth (ch);
  659.     }
  660.     if (width > maxWidth) {
  661.       ch = buf [i + j];
  662.       while (j > 0 && ch != ' ' && ch != '-') {
  663.         j--;
  664.         ch = buf [i + j];
  665.       }
  666.     }
  667.     if (ch == '\n' || ch == '\r') {
  668.       buf [i + j] = '\0';
  669.       Nlm_StaticPrompt (g, buf + i, 0, 0, Nlm_systemFont, 'l');
  670.       i += j + 1;
  671.     } else {
  672.       buf [i + j] = '\0';
  673.       Nlm_StaticPrompt (g, buf + i, 0, 0, Nlm_systemFont, 'l');
  674.       buf [i + j] = ch;
  675.       i += j;
  676.     }
  677.   }
  678.   Nlm_GetPosition (g, &r);
  679.   margin = r.right;
  680.   Nlm_Break ((Nlm_GraphiC) w);
  681.   b [0] = NULL;
  682.   b [1] = NULL;
  683.   b [2] = NULL;
  684.   switch (key) {
  685.     case KEY_OK:
  686.       if (severity == SEV_ERROR) {
  687.         b [0] = Nlm_PushButton (w, "OK", Nlm_MssgErrorProc);
  688.       } else if (severity == SEV_FATAL) {
  689.         b [0] = Nlm_PushButton (w, "OK", Nlm_MssgFatalProc);
  690.       } else {
  691.         b [0] = Nlm_PushButton (w, "OK", Nlm_MssgOkayProc);
  692.       }
  693.       break;
  694.     case KEY_RC:
  695.       b [0] = Nlm_PushButton (w, "Retry", Nlm_MssgRetryProc);
  696.       Nlm_Advance ((Nlm_GraphiC) w);
  697.       b [1] = Nlm_PushButton (w, "Cancel", Nlm_MssgCancelProc);
  698.       break;
  699.     case KEY_ARI:
  700.       b [0] = Nlm_PushButton (w, "Abort", Nlm_MssgAbortProc);
  701.       Nlm_Advance ((Nlm_GraphiC) w);
  702.       b [1] = Nlm_PushButton (w, "Retry", Nlm_MssgRetryProc);
  703.       Nlm_Advance ((Nlm_GraphiC) w);
  704.       b [2] = Nlm_PushButton (w, "Ignore", Nlm_MssgIgnoreProc);
  705.       break;
  706.     case KEY_YN:
  707.       b [0] = Nlm_PushButton (w, "Yes", Nlm_MssgYesProc);
  708.       Nlm_Advance ((Nlm_GraphiC) w);
  709.       b [1] = Nlm_PushButton (w, "No", Nlm_MssgNoProc);
  710.       break;
  711.     case KEY_YNC:
  712.       b [0] = Nlm_PushButton (w, "Yes", Nlm_MssgYesProc);
  713.       Nlm_Advance ((Nlm_GraphiC) w);
  714.       b [1] = Nlm_PushButton (w, "No", Nlm_MssgNoProc);
  715.       Nlm_Advance ((Nlm_GraphiC) w);
  716.       b [2] = Nlm_PushButton (w, "Cancel", Nlm_MssgCancelProc);
  717.       break;
  718.     case KEY_OKC:
  719.       b [1] = Nlm_PushButton (w, "OK", Nlm_MssgOkayProc);
  720.       Nlm_Advance ((Nlm_GraphiC) w);
  721.       b [2] = Nlm_PushButton (w, "Cancel", Nlm_MssgCancelProc);
  722.       break;
  723.     case KEY_NONE:
  724.       b [0] = Nlm_PushButton (w, "OK", Nlm_MssgOkayProc);
  725.       break;
  726.     default:
  727.       b [0] = Nlm_PushButton (w, "OK", Nlm_MssgOkayProc);
  728.       break;
  729.   }
  730.   i = 2;
  731.   while (i >= 0 && b [i] == NULL) {
  732.     i--;
  733.   }
  734.   if (i >= 0) {
  735.     Nlm_GetPosition (b [i], &r);
  736.     delta = (margin - r.right) / 2;
  737.     if (delta > 0) {
  738.       while (i >= 0) {
  739.         Nlm_GetPosition (b [i], &r);
  740.         Nlm_OffsetRect (&r, delta, 0);
  741.         Nlm_SetPosition (b [i], &r);
  742.         i--;
  743.       }
  744.     } else if (delta < 0) {
  745.       Nlm_GetPosition (g, &r);
  746.       Nlm_OffsetRect (&r, -delta, 0);
  747.       Nlm_SetPosition (g, &r);
  748.     }
  749.   }
  750.   Nlm_DoShow ((Nlm_GraphiC) w, TRUE, TRUE);
  751.   Nlm_ArrowCursor ();
  752.   errorBoxUp = TRUE;
  753.   errorBoxRsult = 0;
  754.   while (errorBoxUp) {
  755.     Nlm_ProcessExternalEvent ();
  756.   }
  757.   Nlm_ProcessAnEvent ();
  758.   Nlm_DoRemove ((Nlm_GraphiC) w, TRUE);
  759.   rsult = errorBoxRsult;
  760. #endif
  761. #ifdef WIN_MSWIN
  762.   wtype = MB_OK;
  763.   switch (key) {
  764.     case KEY_OK:
  765.       if (severity == SEV_ERROR) {
  766.         wtype = MB_OK;
  767.       } else if (severity == SEV_FATAL) {
  768.         wtype = MB_OK;
  769.       } else {
  770.         wtype = MB_OK;
  771.       }
  772.       break;
  773.     case KEY_RC:
  774.       wtype = MB_RETRYCANCEL;
  775.       break;
  776.     case KEY_ARI:
  777.       wtype = MB_ABORTRETRYIGNORE;
  778.       break;
  779.     case KEY_YN:
  780.       wtype = MB_YESNO;
  781.       break;
  782.     case KEY_YNC:
  783.       wtype = MB_YESNOCANCEL;
  784.       break;
  785.     case KEY_OKC:
  786.       wtype = MB_OKCANCEL;
  787.       break;
  788.     case KEY_NONE:
  789.       wtype = MB_OK;
  790.       break;
  791.     default:
  792.       break;
  793.   }
  794.   answer = MessageBox (Nlm_currentHWnd, buf, "", wtype);
  795.   switch (answer) {
  796.     case IDNO:
  797.       rsult = ANS_NO;
  798.       break;
  799.     case IDYES:
  800.       rsult = ANS_YES;
  801.       break;
  802.     case IDOK:
  803.       rsult = ANS_OK;
  804.       break;
  805.     case IDRETRY:
  806.       rsult = ANS_RETRY;
  807.       break;
  808.     case IDABORT:
  809.       rsult = ANS_ABORT;
  810.       break;
  811.     case IDCANCEL:
  812.       rsult = ANS_CANCEL;
  813.       break;
  814.     case IDIGNORE:
  815.       rsult = ANS_IGNORE;
  816.       break;
  817.     default:
  818.       break;
  819.   }
  820. #endif
  821. #ifdef WIN_MOTIF
  822.   w = Nlm_ModalWindow (-50, -20, -20, -20, NULL);
  823.   g = Nlm_HiddenGroup (w, 0, 10, NULL);
  824.   Nlm_GetNextPosition (g, &npt);
  825.   npt.x += 6;
  826.   Nlm_SetNextPosition (g, npt);
  827.   i = 0;
  828.   while (Nlm_StringLen (buf + i) > 0) {
  829.     width = 0;
  830.     j = 0;
  831.     while (buf [i + j] == ' ') {
  832.       i++;
  833.     }
  834.     ch = buf [i + j];
  835.     width += Nlm_CharWidth (ch);
  836.     while (ch != '\0' && ch != '\n' && ch != '\r' && width <= maxWidth) {
  837.       j++;
  838.       ch = buf [i + j];
  839.       width += Nlm_CharWidth (ch);
  840.     }
  841.     if (width > maxWidth) {
  842.       ch = buf [i + j];
  843.       while (j > 0 && ch != ' ' && ch != '-') {
  844.         j--;
  845.         ch = buf [i + j];
  846.       }
  847.     }
  848.     if (ch == '\n' || ch == '\r') {
  849.       buf [i + j] = '\0';
  850.       Nlm_StaticPrompt (g, buf + i, 0, 0, Nlm_systemFont, 'l');
  851.       i += j + 1;
  852.     } else {
  853.       buf [i + j] = '\0';
  854.       Nlm_StaticPrompt (g, buf + i, 0, 0, Nlm_systemFont, 'l');
  855.       buf [i + j] = ch;
  856.       i += j;
  857.     }
  858.   }
  859.   Nlm_GetPosition (g, &r);
  860.   margin = r.right;
  861.   Nlm_Break ((Nlm_GraphiC) w);
  862.   b [0] = NULL;
  863.   b [1] = NULL;
  864.   b [2] = NULL;
  865.   switch (key) {
  866.     case KEY_OK:
  867.       if (severity == SEV_ERROR) {
  868.         b [0] = Nlm_PushButton (w, "OK", Nlm_MssgErrorProc);
  869.       } else if (severity == SEV_FATAL) {
  870.         b [0] = Nlm_PushButton (w, "OK", Nlm_MssgFatalProc);
  871.       } else {
  872.         b [0] = Nlm_PushButton (w, "OK", Nlm_MssgOkayProc);
  873.       }
  874.       break;
  875.     case KEY_RC:
  876.       b [0] = Nlm_PushButton (w, "Retry", Nlm_MssgRetryProc);
  877.       Nlm_Advance ((Nlm_GraphiC) w);
  878.       b [1] = Nlm_PushButton (w, "Cancel", Nlm_MssgCancelProc);
  879.       break;
  880.     case KEY_ARI:
  881.       b [0] = Nlm_PushButton (w, "Abort", Nlm_MssgAbortProc);
  882.       Nlm_Advance ((Nlm_GraphiC) w);
  883.       b [1] = Nlm_PushButton (w, "Retry", Nlm_MssgRetryProc);
  884.       Nlm_Advance ((Nlm_GraphiC) w);
  885.       b [2] = Nlm_PushButton (w, "Ignore", Nlm_MssgIgnoreProc);
  886.       break;
  887.     case KEY_YN:
  888.       b [0] = Nlm_PushButton (w, "Yes", Nlm_MssgYesProc);
  889.       Nlm_Advance ((Nlm_GraphiC) w);
  890.       b [1] = Nlm_PushButton (w, "No", Nlm_MssgNoProc);
  891.       break;
  892.     case KEY_YNC:
  893.       b [0] = Nlm_PushButton (w, "Yes", Nlm_MssgYesProc);
  894.       Nlm_Advance ((Nlm_GraphiC) w);
  895.       b [1] = Nlm_PushButton (w, "No", Nlm_MssgNoProc);
  896.       Nlm_Advance ((Nlm_GraphiC) w);
  897.       b [2] = Nlm_PushButton (w, "Cancel", Nlm_MssgCancelProc);
  898.       break;
  899.     case KEY_OKC:
  900.       b [1] = Nlm_PushButton (w, "OK", Nlm_MssgOkayProc);
  901.       Nlm_Advance ((Nlm_GraphiC) w);
  902.       b [2] = Nlm_PushButton (w, "Cancel", Nlm_MssgCancelProc);
  903.       break;
  904.     case KEY_NONE:
  905.       b [0] = Nlm_PushButton (w, "OK", Nlm_MssgOkayProc);
  906.       break;
  907.     default:
  908.       b [0] = Nlm_PushButton (w, "OK", Nlm_MssgOkayProc);
  909.       break;
  910.   }
  911.   i = 2;
  912.   while (i >= 0 && b [i] == NULL) {
  913.     i--;
  914.   }
  915.   if (i >= 0) {
  916.     Nlm_GetPosition (b [i], &r);
  917.     delta = (margin - r.right) / 2;
  918.     if (delta > 0) {
  919.       while (i >= 0) {
  920.         Nlm_GetPosition (b [i], &r);
  921.         Nlm_OffsetRect (&r, delta, 0);
  922.         Nlm_SetPosition (b [i], &r);
  923.         i--;
  924.       }
  925.     } else if (delta < 0) {
  926.       Nlm_GetPosition (g, &r);
  927.       Nlm_OffsetRect (&r, -delta, 0);
  928.       Nlm_SetPosition (g, &r);
  929.     }
  930.   }
  931.   Nlm_DoShow ((Nlm_GraphiC) w, TRUE, TRUE);
  932.   errorBoxUp = TRUE;
  933.   errorBoxRsult = 0;
  934.   while (errorBoxUp) {
  935.     Nlm_ProcessAnEvent ();
  936.   }
  937.   Nlm_DoRemove ((Nlm_GraphiC) w, TRUE);
  938.   rsult = errorBoxRsult;
  939. #endif
  940.   Nlm_MemFree (buf);
  941.   return (MsgAnswer) rsult;
  942. }
  943.  
  944. typedef struct monitextra {
  945.   Nlm_WindoW   wind;
  946.   Nlm_PaneL    pnl;
  947. } Nlm_VibMonExtra, PNTR Nlm_VibMonPtr;
  948.  
  949. static void Nlm_SelectMonitor (Nlm_WindoW w)
  950.  
  951. {
  952.   Nlm_WindowTool  wptr;
  953. #ifdef WIN_MOTIF
  954.   Nlm_ShellTool   shl;
  955. #endif
  956.  
  957.   wptr = Nlm_ParentWindowPtr ((Nlm_GraphiC) w);
  958. #ifdef WIN_MAC
  959.   SelectWindow (wptr);
  960.   SetPort (wptr);
  961.   Nlm_SetUpdateRegion (wptr);
  962.   Nlm_ResetDrawingTools ();
  963. #endif
  964. #ifdef WIN_MSWIN
  965.   BringWindowToTop (wptr);
  966.   Nlm_currentHDC = Nlm_ParentWindowPort ((Nlm_GraphiC) w);
  967.   Nlm_currentHWnd = wptr;
  968. #endif
  969. #ifdef WIN_MOTIF
  970.   if (Nlm_currentXDisplay != NULL) {
  971.     shl = Nlm_ParentWindowShell ((Nlm_GraphiC) w);
  972.     XMapRaised (Nlm_currentXDisplay, XtWindow (shl));
  973.   }
  974. #endif
  975.   Nlm_currentWindowTool = wptr;
  976. }
  977.  
  978. static int Nlm_VibMonStrValue (Nlm_MonitorPtr mon)
  979.  
  980. {
  981.   Nlm_VibMonPtr  vmp;
  982.   Nlm_PaneL      pnl;
  983.   Nlm_RecT       r;
  984.   Nlm_WindoW     tempPort;
  985.   Nlm_WindoW     wind;
  986. #ifdef WIN_MOTIF
  987.   Nlm_Uint4      tempBackColor;
  988.   Nlm_Uint4      tempForeColor;
  989.   Nlm_Int2       tempXOffset;
  990.   Nlm_Int2       tempYOffset;
  991.   Window         tempXWind;
  992. #endif
  993.  
  994.   if (mon == NULL || mon->type != MonType_Str || mon->extra == NULL) {
  995.     return 0;
  996.   }
  997.   vmp = (Nlm_VibMonPtr) mon->extra;
  998.   pnl = vmp->pnl;
  999.   wind = vmp->wind;
  1000.   tempPort = Nlm_CurrentWindow ();
  1001. #ifdef WIN_MOTIF
  1002.   tempXWind = Nlm_currentXWindow;
  1003.   tempBackColor = Nlm_XbackColor;
  1004.   tempForeColor = Nlm_XforeColor;
  1005.   tempXOffset = Nlm_XOffset;
  1006.   tempYOffset = Nlm_YOffset;
  1007. #endif
  1008.   Nlm_UseWindow (wind);
  1009.   Nlm_SelectMonitor (wind);
  1010.   Nlm_Select (pnl);
  1011.   Nlm_GetRect ((Nlm_GraphiC) pnl, &r);
  1012.   Nlm_InsetRect (&r, 2, 2);
  1013.   Nlm_DrawString (&r, (Nlm_CharPtr) mon->strValue, 'l', FALSE);
  1014.   Nlm_UseWindow (tempPort);
  1015. #ifdef WIN_MOTIF
  1016.   Nlm_currentXWindow = tempXWind;
  1017.   Nlm_XbackColor = tempBackColor;
  1018.   Nlm_XforeColor = tempForeColor;
  1019.   Nlm_XOffset = tempXOffset;
  1020.   Nlm_YOffset = tempYOffset;
  1021.   if (Nlm_currentXDisplay != NULL) {
  1022.     XSync (Nlm_currentXDisplay, FALSE);
  1023.   }
  1024. #endif
  1025.   return 0;
  1026. }
  1027.  
  1028. static int Nlm_VibMonIntValue (Nlm_MonitorPtr mon)
  1029.  
  1030. {
  1031.   Nlm_Int4       from;
  1032.   Nlm_VibMonPtr  vmp;
  1033.   Nlm_PaneL      pnl;
  1034.   Nlm_RecT       r;
  1035.   Nlm_Int4       range;
  1036.   Nlm_Int2       right;
  1037.   Nlm_WindoW     tempPort;
  1038.   Nlm_Int4       to;
  1039.   Nlm_Int4       value;
  1040.   Nlm_Int4       width;
  1041.   Nlm_WindoW     wind;
  1042. #ifdef WIN_MOTIF
  1043.   Nlm_Uint4      tempBackColor;
  1044.   Nlm_Uint4      tempForeColor;
  1045.   Nlm_Int2       tempXOffset;
  1046.   Nlm_Int2       tempYOffset;
  1047.   Window         tempXWind;
  1048. #endif
  1049.  
  1050.   if (mon == NULL || mon->type != MonType_Int || mon->extra == NULL) {
  1051.     return 0;
  1052.   }
  1053.   vmp = (Nlm_VibMonPtr) mon->extra;
  1054.   from = MIN (mon->num1, mon->num2);
  1055.   to = MAX (mon->num1, mon->num2);
  1056.   range = to - from;
  1057.   value = mon->intValue;
  1058.   value = MAX (value, from);
  1059.   value = MIN (value, to);
  1060.   value -= from;
  1061.   pnl = vmp->pnl;
  1062.   wind = vmp->wind;
  1063.   tempPort = Nlm_CurrentWindow ();
  1064. #ifdef WIN_MOTIF
  1065.   tempXWind = Nlm_currentXWindow;
  1066.   tempBackColor = Nlm_XbackColor;
  1067.   tempForeColor = Nlm_XforeColor;
  1068.   tempXOffset = Nlm_XOffset;
  1069.   tempYOffset = Nlm_YOffset;
  1070. #endif
  1071.   Nlm_UseWindow (wind);
  1072.   Nlm_SelectMonitor (wind);
  1073.   Nlm_Select (pnl);
  1074.   Nlm_GetRect ((Nlm_GraphiC) pnl, &r);
  1075.   Nlm_FrameRect (&r);
  1076.   Nlm_InsetRect (&r, 2, 2);
  1077.   value = MAX (value, 0);
  1078.   value = MIN (value, range);
  1079.   width = (Nlm_Int4) (r.right - r.left);
  1080.   right = r.right;
  1081.   r.right = r.left + (Nlm_Int2) (width * value / range);
  1082. #ifdef DCLAP
  1083. #ifdef WIN_MOTIF
  1084.     /* my motif aint' showing any progress bar... */
  1085.   Nlm_Black();
  1086. #endif
  1087. #endif
  1088.  
  1089.   Nlm_PaintRect (&r);
  1090.   r.left = r.right;
  1091.   r.right = right;
  1092.   Nlm_EraseRect (&r);
  1093.   Nlm_UseWindow (tempPort);
  1094. #ifdef WIN_MOTIF
  1095.   Nlm_currentXWindow = tempXWind;
  1096.   Nlm_XbackColor = tempBackColor;
  1097.   Nlm_XforeColor = tempForeColor;
  1098.   Nlm_XOffset = tempXOffset;
  1099.   Nlm_YOffset = tempYOffset;
  1100.   if (Nlm_currentXDisplay != NULL) {
  1101.     XSync (Nlm_currentXDisplay, FALSE);
  1102.   }
  1103. #endif
  1104.   return 0;
  1105. }
  1106.  
  1107. static int Nlm_VibMonCreate (Nlm_MonitorPtr mon)
  1108.  
  1109. {
  1110.   Nlm_VibMonPtr  vmp;
  1111.   Nlm_PaneL      pnl;
  1112.   Nlm_WindoW     wind;
  1113.  
  1114.   if (mon != NULL) {
  1115.     vmp = (Nlm_VibMonPtr) Nlm_MemNew (sizeof (Nlm_VibMonExtra));
  1116.     mon->extra = (Nlm_VoidPtr) vmp;
  1117.     if (vmp != NULL) {
  1118.       wind = Nlm_FixedWindow (-50, -90, -10, -10, (Nlm_CharPtr) mon->strTitle, NULL);
  1119.       if (mon->type == MonType_Int) {
  1120.         pnl = Nlm_SimplePanel (wind, 200, 20, NULL);
  1121.       } else if (mon->type == MonType_Str) {
  1122.         pnl = Nlm_SimplePanel (wind, Nlm_stdCharWidth * (Nlm_Int2) mon->num1 + 6,
  1123.                                Nlm_stdLineHeight + 4, NULL);
  1124.       } else {
  1125.         pnl = Nlm_SimplePanel (wind, 200, 20, NULL);
  1126.       }
  1127.       vmp->wind = wind;
  1128.       vmp->pnl = pnl;
  1129.       Nlm_Show (wind);
  1130.     }
  1131.   }
  1132.   return TRUE;
  1133. }
  1134.  
  1135. static int Nlm_VibMonDestroy (Nlm_MonitorPtr mon)
  1136.  
  1137. {
  1138.   Nlm_VibMonPtr  vmp;
  1139.  
  1140.   if (mon != NULL) {
  1141.     vmp = (Nlm_VibMonPtr) mon->extra;
  1142.     if (vmp != NULL) {
  1143.       Nlm_Remove (vmp->wind);
  1144.       Nlm_MemFree (vmp);
  1145.     }
  1146.   }
  1147.   return 0;
  1148. }
  1149.  
  1150. static int LIBCALLBACK Nlm_VibMonitorHook (Nlm_MonitorPtr mon, MonCode code)
  1151.  
  1152. {
  1153.   switch (code) {
  1154.     case MonCode_Create :
  1155.       return Nlm_VibMonCreate (mon);
  1156.       break;
  1157.     case MonCode_Destroy :
  1158.       return Nlm_VibMonDestroy (mon);
  1159.       break;
  1160.     case MonCode_IntValue :
  1161.       return Nlm_VibMonIntValue (mon);
  1162.       break;
  1163.     case MonCode_StrValue :
  1164.       return Nlm_VibMonStrValue (mon);
  1165.       break;
  1166.     default :
  1167.       break;
  1168.   }
  1169.   return 0;
  1170. }
  1171.  
  1172. static void LIBCALLBACK Nlm_VibBeepHook (void)
  1173.  
  1174. {
  1175. #ifdef OS_MAC
  1176.   SysBeep (60);
  1177. #endif
  1178. #ifdef WIN_MSWIN
  1179.   MessageBeep (0);
  1180. #endif
  1181. #ifdef WIN_MOTIF
  1182.   if (Nlm_currentXDisplay != NULL) {
  1183.     XBell (Nlm_currentXDisplay, 0);
  1184.   }
  1185. #endif
  1186. }
  1187.  
  1188. extern void Nlm_InitVibrantHooks (void)
  1189.  
  1190. {
  1191.   Nlm_SetBeepHook (Nlm_VibBeepHook);
  1192.   Nlm_SetMonitorHook (Nlm_VibMonitorHook);
  1193.   Nlm_SetMessageHook (Nlm_VibMessageHook);
  1194. }
  1195.  
  1196. extern void Nlm_MousePosition (Nlm_PointPtr pt)
  1197.  
  1198. {
  1199. #ifdef WIN_MAC
  1200.   Nlm_PointTool  ptool;
  1201.  
  1202.   GetMouse (&ptool);
  1203.   if (pt != NULL) {
  1204.     Nlm_PointToolToPoinT (ptool, pt);
  1205.   }
  1206. #endif
  1207. #ifdef WIN_MSWIN
  1208.   Nlm_PointTool  ptool;
  1209.  
  1210.   if (pt != NULL && Nlm_currentHWnd != NULL) {
  1211.     GetCursorPos (&ptool);
  1212.     ScreenToClient (Nlm_currentHWnd, &ptool);
  1213.     Nlm_PointToolToPoinT (ptool, pt);
  1214.   }
  1215. #endif
  1216. #ifdef WIN_MOTIF
  1217. #endif
  1218. }
  1219.  
  1220. extern Nlm_Boolean Nlm_MouseButton (void)
  1221.  
  1222. {
  1223. #ifdef WIN_MAC
  1224.   return (Button ());
  1225. #endif
  1226. #ifdef WIN_MSWIN
  1227.   return (Nlm_Boolean) ((GetAsyncKeyState (VK_LBUTTON) & 0x8000) != 0);
  1228. #endif
  1229. #ifdef WIN_MOTIF
  1230.   return FALSE;
  1231. #endif
  1232. }
  1233.  
  1234. extern Nlm_Int4 Nlm_ComputerTime (void)
  1235.  
  1236. {
  1237. #ifdef WIN_MAC
  1238.   return (TickCount ());
  1239. #endif
  1240. #ifdef WIN_MSWIN
  1241.   return (GetCurrentTime ());
  1242. #endif
  1243. #ifdef WIN_MOTIF
  1244. #endif
  1245. }
  1246.  
  1247. extern void Nlm_Version (Nlm_CharPtr vsn, Nlm_sizeT maxsize)
  1248.  
  1249. {
  1250.   Nlm_StringNCpy (vsn, "NCBI VIBRANT Version 0.8 (8 May 91)", maxsize);
  1251. }
  1252.  
  1253. extern void Nlm_Advance (Nlm_Handle a)
  1254.  
  1255. {
  1256.   Nlm_BoxData  bdata;
  1257.  
  1258.   if (a != NULL) {
  1259.     Nlm_GetBoxData ((Nlm_BoX) a, &bdata);
  1260.     bdata.nextPoint.y = bdata.topRow;
  1261.     bdata.nextPoint.x = bdata.nextCol;
  1262.     Nlm_SetBoxData ((Nlm_BoX) a, &bdata);
  1263.   }
  1264. }
  1265.  
  1266. extern void Nlm_Break (Nlm_Handle a)
  1267.  
  1268. {
  1269.   Nlm_BoxData  bdata;
  1270.  
  1271.   if (a != NULL) {
  1272.     Nlm_GetBoxData ((Nlm_BoX) a, &bdata);
  1273.     bdata.topRow = bdata.limitPoint.y + bdata.ySpacing;
  1274.     bdata.nextCol = bdata.resetPoint.x;
  1275.     bdata.nextPoint.y = bdata.topRow;
  1276.     bdata.nextPoint.x = bdata.nextCol;
  1277.     Nlm_SetBoxData ((Nlm_BoX) a, &bdata);
  1278.   }
  1279. }
  1280.  
  1281. extern void Nlm_RecordRect (Nlm_GraphiC a, Nlm_RectPtr r)
  1282.  
  1283. {
  1284.   Nlm_BoxData  bdata;
  1285.   Nlm_Int2     nc;
  1286.   Nlm_Int2     nr;
  1287.  
  1288.   if (a != NULL && r != NULL) {
  1289.     Nlm_GetBoxData ((Nlm_BoX) a, &bdata);
  1290.     nr = r->bottom;
  1291.     if (nr > bdata.limitPoint.y) {
  1292.       bdata.limitPoint.y = nr;
  1293.     }
  1294.     nc = r->right;
  1295.     if (nc > bdata.limitPoint.x) {
  1296.       bdata.limitPoint.x = nc;
  1297.     }
  1298.     nc = r->right + bdata.xSpacing;
  1299.     if (nc > bdata.nextCol) {
  1300.       bdata.nextCol = nc;
  1301.     }
  1302.     Nlm_SetBoxData ((Nlm_BoX) a, &bdata);
  1303.   }
  1304. }
  1305.  
  1306. extern void Nlm_NextPosition (Nlm_GraphiC a, Nlm_RectPtr r)
  1307.  
  1308. {
  1309.   Nlm_BoxData  bdata;
  1310.  
  1311.   if (a != NULL && r != NULL) {
  1312.     Nlm_GetBoxData ((Nlm_BoX) a, &bdata);
  1313.     bdata.nextPoint.y = r->bottom + bdata.ySpacing;
  1314.     Nlm_SetBoxData ((Nlm_BoX) a, &bdata);
  1315.   }
  1316. }
  1317.  
  1318. extern void Nlm_SetNextPosition (Nlm_Handle a, Nlm_PoinT nps)
  1319.  
  1320. {
  1321.   Nlm_BoxData  bdata;
  1322.  
  1323.   if (a != NULL) {
  1324.     Nlm_GetBoxData ((Nlm_BoX) a, &bdata);
  1325.     bdata.nextPoint = nps;
  1326.     bdata.topRow = nps.y;
  1327.     Nlm_SetBoxData ((Nlm_BoX) a, &bdata);
  1328.   }
  1329. }
  1330.  
  1331. extern void Nlm_GetNextPosition (Nlm_Handle a, Nlm_PointPtr nps)
  1332.  
  1333. {
  1334.   Nlm_BoxData  bdata;
  1335.  
  1336.   if (a != NULL && nps != NULL) {
  1337.     Nlm_GetBoxData ((Nlm_BoX) a, &bdata);
  1338.     *nps = bdata.nextPoint;
  1339.   }
  1340. }
  1341.  
  1342. extern Nlm_GphPrcsPtr Nlm_GetClassPtr (Nlm_GraphiC a)
  1343.  
  1344. {
  1345.   Nlm_GphPrcsPtr   classPtr;
  1346.   Nlm_GraphicData  gdata;
  1347.  
  1348.   classPtr = NULL;
  1349.   if (a != NULL) {
  1350.     Nlm_GetGraphicData (a, &gdata);
  1351.     classPtr = gdata.classptr;
  1352.   }
  1353.   return classPtr;
  1354. }
  1355.  
  1356. #ifdef WIN_MAC
  1357. extern Nlm_Boolean Nlm_DoClick (Nlm_GraphiC a, Nlm_PoinT pt)
  1358.  
  1359. {
  1360.   Nlm_GphPrcsPtr  classPtr;
  1361.   Nlm_Boolean     cont;
  1362.   Nlm_Boolean     (*clk) PROTO((Nlm_GraphiC, Nlm_PoinT));
  1363.   Nlm_Boolean     rsult;
  1364.  
  1365.   rsult = FALSE;
  1366.   cont = TRUE;
  1367.   classPtr = Nlm_GetClassPtr (a);
  1368.   while (classPtr != NULL && cont) {
  1369.     clk = classPtr->click;
  1370.     if (clk != NULL) {
  1371.       rsult = clk (a, pt);
  1372.       cont = FALSE;
  1373.     } else {
  1374.       classPtr = classPtr->ancestor;
  1375.     }
  1376.   }
  1377.   return rsult;
  1378. }
  1379.  
  1380. extern Nlm_Boolean Nlm_DoKey (Nlm_GraphiC a, Nlm_Char ch)
  1381.  
  1382. {
  1383.   Nlm_GphPrcsPtr  classPtr;
  1384.   Nlm_Boolean     cont;
  1385.   Nlm_Boolean     (*ky) PROTO((Nlm_GraphiC, Nlm_Char));
  1386.   Nlm_Boolean     rsult;
  1387.  
  1388.   rsult = FALSE;
  1389.   cont = TRUE;
  1390.   classPtr = Nlm_GetClassPtr (a);
  1391.   while (classPtr != NULL && cont) {
  1392.     ky = classPtr->key;
  1393.     if (ky != NULL) {
  1394.       rsult = ky (a, ch);
  1395.       cont = FALSE;
  1396.     } else {
  1397.       classPtr = classPtr->ancestor;
  1398.     }
  1399.   }
  1400.   return rsult;
  1401. }
  1402.  
  1403. extern void Nlm_DoDraw (Nlm_GraphiC a)
  1404.  
  1405. {
  1406.   Nlm_GphPrcsPtr  classPtr;
  1407.   Nlm_Boolean     cont;
  1408.   void            (*drw) PROTO((Nlm_GraphiC));
  1409.  
  1410.   cont = TRUE;
  1411.   classPtr = Nlm_GetClassPtr (a);
  1412.   while (classPtr != NULL && cont) {
  1413.     drw = classPtr->draw;
  1414.     if (drw != NULL) {
  1415.       drw (a);
  1416.       cont = FALSE;
  1417.     } else {
  1418.       classPtr = classPtr->ancestor;
  1419.     }
  1420.   }
  1421. }
  1422.  
  1423. extern Nlm_Boolean Nlm_DoIdle (Nlm_GraphiC a, Nlm_PoinT pt)
  1424.  
  1425. {
  1426.   Nlm_GphPrcsPtr  classPtr;
  1427.   Nlm_Boolean     cont;
  1428.   Nlm_Boolean     (*idl) PROTO((Nlm_GraphiC, Nlm_PoinT));
  1429.   Nlm_Boolean     rsult;
  1430.  
  1431.   rsult = FALSE;
  1432.   cont = TRUE;
  1433.   classPtr = Nlm_GetClassPtr (a);
  1434.   while (classPtr != NULL && cont) {
  1435.     idl = classPtr->idle;
  1436.     if (idl != NULL) {
  1437.       rsult = idl (a, pt);
  1438.       cont = FALSE;
  1439.     } else {
  1440.       classPtr = classPtr->ancestor;
  1441.     }
  1442.   }
  1443.   return rsult;
  1444. }
  1445. #endif
  1446.  
  1447. #ifdef WIN_MSWIN
  1448. extern Nlm_Boolean Nlm_DoCommand (Nlm_GraphiC a)
  1449.  
  1450. {
  1451.   Nlm_GphPrcsPtr  classPtr;
  1452.   Nlm_Boolean     cont;
  1453.   Nlm_Boolean     (*cmd) PROTO((Nlm_GraphiC));
  1454.   Nlm_Boolean     rsult;
  1455.  
  1456.   rsult = FALSE;
  1457.   cont = TRUE;
  1458.   classPtr = Nlm_GetClassPtr (a);
  1459.   while (classPtr != NULL && cont) {
  1460.     cmd = classPtr->command;
  1461.     if (cmd != NULL) {
  1462.       rsult = cmd (a);
  1463.       cont = FALSE;
  1464.     } else {
  1465.       classPtr = classPtr->ancestor;
  1466.     }
  1467.   }
  1468.   return rsult;
  1469. }
  1470. #endif
  1471.  
  1472. #ifdef WIN_MOTIF
  1473. extern void Nlm_DoCallback (Nlm_GraphiC a)
  1474.  
  1475. {
  1476.   Nlm_GphPrcsPtr  classPtr;
  1477.   Nlm_Boolean     cont;
  1478.   void            (*clb) PROTO((Nlm_GraphiC));
  1479.  
  1480.   cont = TRUE;
  1481.   classPtr = Nlm_GetClassPtr (a);
  1482.   while (classPtr != NULL && cont) {
  1483.     clb = classPtr->callback;
  1484.     if (clb != NULL) {
  1485.       clb (a);
  1486.       cont = FALSE;
  1487.     } else {
  1488.       classPtr = classPtr->ancestor;
  1489.     }
  1490.   }
  1491. }
  1492. #endif
  1493.  
  1494. extern void Nlm_DoShow (Nlm_GraphiC a, Nlm_Boolean setFlag, Nlm_Boolean savePort)
  1495.  
  1496. {
  1497.   Nlm_GphPrcsPtr  classPtr;
  1498.   Nlm_Boolean     cont;
  1499.   void            (*shw) PROTO((Nlm_GraphiC, Nlm_Boolean, Nlm_Boolean));
  1500.  
  1501.   cont = TRUE;
  1502.   classPtr = Nlm_GetClassPtr (a);
  1503.   while (classPtr != NULL && cont) {
  1504.     shw = classPtr->show;
  1505.     if (shw != NULL) {
  1506.       shw (a, setFlag, savePort);
  1507.       cont = FALSE;
  1508.     } else {
  1509.       classPtr = classPtr->ancestor;
  1510.     }
  1511.   }
  1512. }
  1513.  
  1514. extern void Nlm_DoHide (Nlm_GraphiC a, Nlm_Boolean setFlag, Nlm_Boolean savePort)
  1515.  
  1516. {
  1517.   Nlm_GphPrcsPtr  classPtr;
  1518.   Nlm_Boolean     cont;
  1519.   void            (*hid) PROTO((Nlm_GraphiC, Nlm_Boolean, Nlm_Boolean));
  1520.  
  1521.   cont = TRUE;
  1522.   classPtr = Nlm_GetClassPtr (a);
  1523.   while (classPtr != NULL && cont) {
  1524.     hid = classPtr->hide;
  1525.     if (hid != NULL) {
  1526.       hid (a, setFlag, savePort);
  1527.       cont = FALSE;
  1528.     } else {
  1529.       classPtr = classPtr->ancestor;
  1530.     }
  1531.   }
  1532. }
  1533.  
  1534. extern void Nlm_DoEnable (Nlm_GraphiC a, Nlm_Boolean setFlag, Nlm_Boolean savePort)
  1535.  
  1536. {
  1537.   Nlm_GphPrcsPtr  classPtr;
  1538.   Nlm_Boolean     cont;
  1539.   void            (*enbl) PROTO((Nlm_GraphiC, Nlm_Boolean, Nlm_Boolean));
  1540.  
  1541.   cont = TRUE;
  1542.   classPtr = Nlm_GetClassPtr (a);
  1543.   while (classPtr != NULL && cont) {
  1544.     enbl = classPtr->enable;
  1545.     if (enbl != NULL) {
  1546.       enbl (a, setFlag, savePort);
  1547.       cont = FALSE;
  1548.     } else {
  1549.       classPtr = classPtr->ancestor;
  1550.     }
  1551.   }
  1552. }
  1553.  
  1554. extern void Nlm_DoDisable (Nlm_GraphiC a, Nlm_Boolean setFlag, Nlm_Boolean savePort)
  1555.  
  1556. {
  1557.   Nlm_GphPrcsPtr  classPtr;
  1558.   Nlm_Boolean     cont;
  1559.   void            (*dsbl) PROTO((Nlm_GraphiC, Nlm_Boolean, Nlm_Boolean));
  1560.  
  1561.   cont = TRUE;
  1562.   classPtr = Nlm_GetClassPtr (a);
  1563.   while (classPtr != NULL && cont) {
  1564.     dsbl = classPtr->disable;
  1565.     if (dsbl != NULL) {
  1566.       dsbl (a, setFlag, savePort);
  1567.       cont = FALSE;
  1568.     } else {
  1569.       classPtr = classPtr->ancestor;
  1570.     }
  1571.   }
  1572. }
  1573.  
  1574. extern void Nlm_DoActivate (Nlm_GraphiC a, Nlm_Boolean savePort)
  1575.  
  1576. {
  1577.   void            (*actvate) PROTO((Nlm_GraphiC, Nlm_Boolean));
  1578.   Nlm_Boolean     cont;
  1579.   Nlm_GphPrcsPtr  classPtr;
  1580.  
  1581.   cont = TRUE;
  1582.   classPtr = Nlm_GetClassPtr (a);
  1583.   while (classPtr != NULL && cont) {
  1584.     actvate = classPtr->activate;
  1585.     if (actvate != NULL) {
  1586.       actvate (a, savePort);
  1587.       cont = FALSE;
  1588.     } else {
  1589.       classPtr = classPtr->ancestor;
  1590.     }
  1591.   }
  1592. }
  1593.  
  1594. extern void Nlm_DoDeactivate (Nlm_GraphiC a, Nlm_Boolean savePort)
  1595.  
  1596. {
  1597.   Nlm_GphPrcsPtr  classPtr;
  1598.   Nlm_Boolean     cont;
  1599.   void            (*deactvate) PROTO((Nlm_GraphiC, Nlm_Boolean));
  1600.  
  1601.   cont = TRUE;
  1602.   classPtr = Nlm_GetClassPtr (a);
  1603.   while (classPtr != NULL && cont) {
  1604.     deactvate = classPtr->deactivate;
  1605.     if (deactvate != NULL) {
  1606.       deactvate (a, savePort);
  1607.       cont = FALSE;
  1608.     } else {
  1609.       classPtr = classPtr->ancestor;
  1610.     }
  1611.   }
  1612. }
  1613.  
  1614. extern Nlm_Handle Nlm_DoRemove (Nlm_GraphiC a, Nlm_Boolean savePort)
  1615.  
  1616. {
  1617.   Nlm_GphPrcsPtr  classPtr;
  1618.   Nlm_Boolean     cont;
  1619.   void            (*rmv) PROTO((Nlm_GraphiC, Nlm_Boolean));
  1620.  
  1621.   cont = TRUE;
  1622.   Nlm_DoHide (a, TRUE, savePort);
  1623.   classPtr = Nlm_GetClassPtr (a);
  1624.   while (classPtr != NULL && cont) {
  1625.     rmv = classPtr->remove;
  1626.     if (rmv != NULL) {
  1627.       rmv (a, savePort);
  1628.       cont = FALSE;
  1629.     } else {
  1630.       classPtr = classPtr->ancestor;
  1631.     }
  1632.     recentGraphic = NULL;
  1633.     recentBox = NULL;
  1634.   }
  1635.   return NULL;
  1636. }
  1637.  
  1638. extern void Nlm_DoReset (Nlm_GraphiC a, Nlm_Boolean savePort)
  1639.  
  1640. {
  1641.   Nlm_GphPrcsPtr  classPtr;
  1642.   Nlm_Boolean     cont;
  1643.   void            (*rst) PROTO((Nlm_GraphiC, Nlm_Boolean));
  1644.  
  1645.   cont = TRUE;
  1646.   classPtr = Nlm_GetClassPtr (a);
  1647.   while (classPtr != NULL && cont) {
  1648.     rst = classPtr->reset;
  1649.     if (rst != NULL) {
  1650.       rst (a, TRUE);
  1651.       cont = FALSE;
  1652.     } else {
  1653.       classPtr = classPtr->ancestor;
  1654.     }
  1655.   }
  1656. }
  1657.  
  1658. extern void Nlm_DoSelect (Nlm_GraphiC a, Nlm_Boolean savePort)
  1659.  
  1660. {
  1661.   Nlm_GphPrcsPtr  classPtr;
  1662.   Nlm_Boolean     cont;
  1663.   void            (*sel) PROTO((Nlm_GraphiC, Nlm_Boolean));
  1664.  
  1665.   cont = TRUE;
  1666.   classPtr = Nlm_GetClassPtr (a);
  1667.   while (classPtr != NULL && cont) {
  1668.     sel = classPtr->select;
  1669.     if (sel != NULL) {
  1670.       sel (a, savePort);
  1671.       cont = FALSE;
  1672.     } else {
  1673.       classPtr = classPtr->ancestor;
  1674.     }
  1675.   }
  1676. }
  1677.  
  1678. extern Nlm_Int2 Nlm_CountItems (Nlm_Handle a)
  1679.  
  1680. {
  1681.   Nlm_GphPrcsPtr  classPtr;
  1682.   Nlm_Boolean     cont;
  1683.   Nlm_Int2        (*cntitm) PROTO((Nlm_GraphiC));
  1684.   Nlm_Int2        len;
  1685.  
  1686.   cont = TRUE;
  1687.   len = 0;
  1688.   classPtr = Nlm_GetClassPtr ((Nlm_GraphiC)a);
  1689.   while (classPtr != NULL && cont) {
  1690.     cntitm = classPtr->countItems;
  1691.     if (cntitm != NULL) {
  1692.       len = cntitm ((Nlm_GraphiC)a);
  1693.       cont = FALSE;
  1694.     } else {
  1695.       classPtr = classPtr->ancestor;
  1696.     }
  1697.   }
  1698.   return len;
  1699. }
  1700.  
  1701. extern Nlm_GraphiC Nlm_DoLinkIn (Nlm_GraphiC a, Nlm_GraphiC prnt)
  1702.  
  1703. {
  1704.   Nlm_GphPrcsPtr  prntClassPtr;
  1705.   Nlm_Boolean     cont;
  1706.   Nlm_GraphiC     (*lnkIn) PROTO((Nlm_GraphiC, Nlm_GraphiC));
  1707.   Nlm_GraphiC     rsult;
  1708.  
  1709.   cont = TRUE;
  1710.   rsult = NULL;
  1711.   if (a != NULL && prnt != NULL) {
  1712.     cont = TRUE;
  1713.     prntClassPtr = Nlm_GetClassPtr (prnt);
  1714.     while (prntClassPtr != NULL && cont) {
  1715.       lnkIn = prntClassPtr->linkIn;
  1716.       if (lnkIn != NULL) {
  1717.         rsult = lnkIn (a, prnt);
  1718.         cont = FALSE;
  1719.       } else {
  1720.         prntClassPtr = prntClassPtr->ancestor;
  1721.       }
  1722.     }
  1723.   }
  1724.   return rsult;
  1725. }
  1726.  
  1727. extern void Nlm_DoAdjustPrnt (Nlm_GraphiC a, Nlm_RectPtr r,
  1728.                               Nlm_Boolean align, Nlm_Boolean savePort)
  1729.  
  1730. {
  1731.   void            (*adjst) PROTO((Nlm_GraphiC, Nlm_RectPtr, Nlm_Boolean, Nlm_Boolean));
  1732.   Nlm_Boolean     cont;
  1733.   Nlm_GraphiC     p;
  1734.   Nlm_GphPrcsPtr  prntClassPtr;
  1735.  
  1736.   cont = TRUE;
  1737.   if (a != NULL) {
  1738.     p = Nlm_GetParent (a);
  1739.     prntClassPtr = Nlm_GetClassPtr (p);
  1740.     while (prntClassPtr != NULL && cont) {
  1741.       adjst = prntClassPtr->adjustPrnt;
  1742.       if (adjst != NULL) {
  1743.         adjst (a, r, align, savePort);
  1744.         cont = FALSE;
  1745.       } else {
  1746.         prntClassPtr = prntClassPtr->ancestor;
  1747.       }
  1748.     }
  1749.   }
  1750. }
  1751.  
  1752. extern void Nlm_DoSetTitle (Nlm_GraphiC a, Nlm_Int2 item,
  1753.                             Nlm_CharPtr title, Nlm_Boolean savePort)
  1754.  
  1755. {
  1756.   Nlm_GphPrcsPtr  classPtr;
  1757.   Nlm_Boolean     cont;
  1758.   void            (*stttl) PROTO((Nlm_GraphiC, Nlm_Int2, Nlm_CharPtr, Nlm_Boolean));
  1759.  
  1760.   cont = TRUE;
  1761.   classPtr = Nlm_GetClassPtr (a);
  1762.   while (classPtr != NULL && cont) {
  1763.     stttl = classPtr->setTitle;
  1764.     if (stttl != NULL) {
  1765.       stttl (a, item, title, savePort);
  1766.       cont = FALSE;
  1767.     } else {
  1768.       classPtr = classPtr->ancestor;
  1769.     }
  1770.   }
  1771. }
  1772.  
  1773. extern void Nlm_DoGetTitle (Nlm_GraphiC a, Nlm_Int2 item,
  1774.                             Nlm_CharPtr title, Nlm_sizeT maxsize)
  1775.  
  1776. {
  1777.   Nlm_GphPrcsPtr  classPtr;
  1778.   Nlm_Boolean     cont;
  1779.   Nlm_Boolean     failed;
  1780.   void            (*gtttl) PROTO((Nlm_GraphiC, Nlm_Int2, Nlm_CharPtr, Nlm_sizeT));
  1781.  
  1782.   cont = TRUE;
  1783.   failed = TRUE;
  1784.   classPtr = Nlm_GetClassPtr (a);
  1785.   while (classPtr != NULL && cont) {
  1786.     gtttl = classPtr->getTitle;
  1787.     if (gtttl != NULL) {
  1788.       gtttl (a, item, title, maxsize);
  1789.       failed = FALSE;
  1790.       cont = FALSE;
  1791.     } else {
  1792.       classPtr = classPtr->ancestor;
  1793.     }
  1794.   }
  1795.   if (failed) {
  1796.     Nlm_StringNCpy (title, "", maxsize);
  1797.   }
  1798. }
  1799.  
  1800. extern void Nlm_DoSetValue (Nlm_GraphiC a, Nlm_Int2 value, Nlm_Boolean savePort)
  1801.  
  1802. {
  1803.   Nlm_GphPrcsPtr  classPtr;
  1804.   Nlm_Boolean     cont;
  1805.   void            (*stval) PROTO((Nlm_GraphiC, Nlm_Int2, Nlm_Boolean));
  1806.  
  1807.   cont = TRUE;
  1808.   classPtr = Nlm_GetClassPtr (a);
  1809.   while (classPtr != NULL && cont) {
  1810.     stval = classPtr->setValue;
  1811.     if (stval != NULL) {
  1812.       stval (a, value, savePort);
  1813.       cont = FALSE;
  1814.     } else {
  1815.       classPtr = classPtr->ancestor;
  1816.     }
  1817.   }
  1818. }
  1819.  
  1820. extern Nlm_Int2 Nlm_DoGetValue (Nlm_GraphiC a)
  1821.  
  1822. {
  1823.   Nlm_GphPrcsPtr  classPtr;
  1824.   Nlm_Boolean     cont;
  1825.   Nlm_Int2        (*gtval) PROTO((Nlm_GraphiC));
  1826.   Nlm_Int2        value;
  1827.  
  1828.   cont = TRUE;
  1829.   value = 0;
  1830.   classPtr = Nlm_GetClassPtr (a);
  1831.   while (classPtr != NULL && cont) {
  1832.     gtval = classPtr->getValue;
  1833.     if (gtval != NULL) {
  1834.       value = gtval (a);
  1835.       cont = FALSE;
  1836.     } else {
  1837.       classPtr = classPtr->ancestor;
  1838.     }
  1839.   }
  1840.   return value;
  1841. }
  1842.  
  1843. extern void Nlm_DoSetStatus (Nlm_GraphiC a, Nlm_Int2 item,
  1844.                              Nlm_Boolean status, Nlm_Boolean savePort)
  1845.  
  1846. {
  1847.   Nlm_GphPrcsPtr  classPtr;
  1848.   Nlm_Boolean     cont;
  1849.   void            (*ststs) PROTO((Nlm_GraphiC, Nlm_Int2, Nlm_Boolean, Nlm_Boolean));
  1850.  
  1851.   cont = TRUE;
  1852.   classPtr = Nlm_GetClassPtr (a);
  1853.   while (classPtr != NULL && cont) {
  1854.     ststs = classPtr->setStatus;
  1855.     if (ststs != NULL) {
  1856.       ststs (a, item, status, savePort);
  1857.       cont = FALSE;
  1858.     } else {
  1859.       classPtr = classPtr->ancestor;
  1860.     }
  1861.   }
  1862. }
  1863.  
  1864. extern Nlm_Boolean Nlm_DoGetStatus (Nlm_GraphiC a, Nlm_Int2 item)
  1865.  
  1866. {
  1867.   Nlm_GphPrcsPtr  classPtr;
  1868.   Nlm_Boolean     cont;
  1869.   Nlm_Boolean     (*gtsts) PROTO((Nlm_GraphiC, Nlm_Int2));
  1870.   Nlm_Boolean     val;
  1871.  
  1872.   cont = TRUE;
  1873.   val = FALSE;
  1874.   classPtr = Nlm_GetClassPtr (a);
  1875.   while (classPtr != NULL && cont) {
  1876.     gtsts = classPtr->getStatus;
  1877.     if (gtsts != NULL) {
  1878.       val = gtsts (a, item);
  1879.       cont = FALSE;
  1880.     } else {
  1881.       classPtr = classPtr->ancestor;
  1882.     }
  1883.   }
  1884.   return val;
  1885. }
  1886.  
  1887. extern void Nlm_DoSetOffset (Nlm_GraphiC a, Nlm_Int2 horiz,
  1888.                              Nlm_Int2 vert,Nlm_Boolean savePort)
  1889.  
  1890. {
  1891.   Nlm_GphPrcsPtr  classPtr;
  1892.   Nlm_Boolean     cont;
  1893.   void            (*stoff) PROTO((Nlm_GraphiC, Nlm_Int2, Nlm_Int2, Nlm_Boolean));
  1894.  
  1895.   cont = TRUE;
  1896.   classPtr = Nlm_GetClassPtr (a);
  1897.   while (classPtr != NULL && cont) {
  1898.     stoff = classPtr->setOffset;
  1899.     if (stoff != NULL) {
  1900.       stoff (a, horiz, vert, savePort);
  1901.       cont = FALSE;
  1902.     } else {
  1903.       classPtr = classPtr->ancestor;
  1904.     }
  1905.   }
  1906. }
  1907.  
  1908. extern void Nlm_DoGetOffset (Nlm_GraphiC a, Nlm_Int2Ptr horiz, Nlm_Int2Ptr vert)
  1909.  
  1910. {
  1911.   Nlm_GphPrcsPtr  classPtr;
  1912.   Nlm_Boolean     cont;
  1913.   Nlm_Boolean     failed;
  1914.   void            (*gtoff) PROTO((Nlm_GraphiC, Nlm_Int2Ptr, Nlm_Int2Ptr));
  1915.  
  1916.   cont = TRUE;
  1917.   failed = TRUE;
  1918.   classPtr = Nlm_GetClassPtr (a);
  1919.   while (classPtr != NULL && cont) {
  1920.     gtoff = classPtr->getOffset;
  1921.     if (gtoff != NULL) {
  1922.       gtoff (a, horiz, vert);
  1923.       failed = FALSE;
  1924.       cont = FALSE;
  1925.     } else {
  1926.       classPtr = classPtr->ancestor;
  1927.     }
  1928.   }
  1929.   if (failed) {
  1930.     if (horiz != NULL) {
  1931.       *horiz = 0;
  1932.     }
  1933.     if (vert != NULL) {
  1934.       *vert = 0;
  1935.     }
  1936.   }
  1937. }
  1938.  
  1939. extern void Nlm_DoSetPosition (Nlm_GraphiC a, Nlm_RectPtr r, Nlm_Boolean savePort)
  1940.  
  1941. {
  1942.   Nlm_GphPrcsPtr  classPtr;
  1943.   Nlm_Boolean     cont;
  1944.   void            (*stpos) PROTO((Nlm_GraphiC, Nlm_RectPtr, Nlm_Boolean));
  1945.  
  1946.   cont = TRUE;
  1947.   classPtr = Nlm_GetClassPtr (a);
  1948.   while (classPtr != NULL && cont) {
  1949.     stpos = classPtr->setPosition;
  1950.     if (stpos != NULL) {
  1951.       stpos (a, r, savePort);
  1952.       cont = FALSE;
  1953.     } else {
  1954.       classPtr = classPtr->ancestor;
  1955.     }
  1956.   }
  1957. }
  1958.  
  1959. extern void Nlm_DoGetPosition (Nlm_GraphiC a, Nlm_RectPtr r)
  1960.  
  1961. {
  1962.   Nlm_GphPrcsPtr  classPtr;
  1963.   Nlm_Boolean     cont;
  1964.   Nlm_Boolean     failed;
  1965.   void            (*gtpos) PROTO((Nlm_GraphiC, Nlm_RectPtr));
  1966.  
  1967.   cont = TRUE;
  1968.   failed = TRUE;
  1969.   classPtr = Nlm_GetClassPtr (a);
  1970.   while (classPtr != NULL && cont) {
  1971.     gtpos = classPtr->getPosition;
  1972.     if (gtpos != NULL) {
  1973.       gtpos (a, r);
  1974.       failed = FALSE;
  1975.       cont = FALSE;
  1976.     } else {
  1977.       classPtr = classPtr->ancestor;
  1978.     }
  1979.   }
  1980.   if (failed) {
  1981.     if (r != NULL) {
  1982.       Nlm_LoadRect (r, 0, 0, 0, 0);
  1983.     }
  1984.   }
  1985. }
  1986.  
  1987. extern void Nlm_DoSetRange (Nlm_GraphiC a, Nlm_Int2 pgUp,
  1988.                             Nlm_Int2 pgDn, Nlm_Int2 max,
  1989.                             Nlm_Boolean savePort)
  1990.  
  1991. {
  1992.   Nlm_GphPrcsPtr  classPtr;
  1993.   Nlm_Boolean     cont;
  1994.   void            (*rng) PROTO((Nlm_GraphiC, Nlm_Int2, Nlm_Int2, Nlm_Int2, Nlm_Boolean));
  1995.  
  1996.  
  1997.   cont = TRUE;
  1998.   classPtr = Nlm_GetClassPtr (a);
  1999.   while (classPtr != NULL && cont) {
  2000.     rng = classPtr->setRange;
  2001.     if (rng != NULL) {
  2002.       rng (a, pgUp, pgDn, max, savePort);
  2003.       cont = FALSE;
  2004.     } else {
  2005.       classPtr = classPtr->ancestor;
  2006.     }
  2007.   }
  2008. }
  2009.  
  2010. extern Nlm_GraphiC Nlm_DoGainFocus (Nlm_GraphiC a, Nlm_Char ch, Nlm_Boolean savePort)
  2011.  
  2012. {
  2013.   Nlm_GphPrcsPtr  classPtr;
  2014.   Nlm_Boolean     cont;
  2015.   Nlm_GraphiC     rsult;
  2016.   Nlm_GraphiC     (*gainFcs) PROTO((Nlm_GraphiC, Nlm_Char, Nlm_Boolean));
  2017.  
  2018.   cont = TRUE;
  2019.   rsult = NULL;
  2020.   classPtr = Nlm_GetClassPtr (a);
  2021.   while (classPtr != NULL && cont) {
  2022.     gainFcs = classPtr->gainFocus;
  2023.     if (gainFcs != NULL) {
  2024.       rsult = gainFcs (a, ch, savePort);
  2025.       cont = FALSE;
  2026.     } else {
  2027.       classPtr = classPtr->ancestor;
  2028.     }
  2029.   }
  2030.   return rsult;
  2031. }
  2032.  
  2033. extern void Nlm_DoLoseFocus (Nlm_GraphiC a, Nlm_GraphiC excpt, Nlm_Boolean savePort)
  2034.  
  2035. {
  2036.   Nlm_GphPrcsPtr  classPtr;
  2037.   Nlm_Boolean     cont;
  2038.   void            (*loseFcs) PROTO((Nlm_GraphiC, Nlm_GraphiC, Nlm_Boolean));
  2039.  
  2040.   cont = TRUE;
  2041.   classPtr = Nlm_GetClassPtr (a);
  2042.   while (classPtr != NULL && cont) {
  2043.     loseFcs = classPtr->loseFocus;
  2044.     if (loseFcs != NULL) {
  2045.       loseFcs (a, excpt, savePort);
  2046.       cont = FALSE;
  2047.     } else {
  2048.       classPtr = classPtr->ancestor;
  2049.     }
  2050.   }
  2051. }
  2052.  
  2053. extern void Nlm_DoSendChar (Nlm_GraphiC a, Nlm_Char ch, Nlm_Boolean savePort)
  2054.  
  2055. {
  2056.   Nlm_GphPrcsPtr  classPtr;
  2057.   Nlm_Boolean     cont;
  2058.   void            (*sendCh) PROTO((Nlm_GraphiC, Nlm_Char, Nlm_Boolean));
  2059.  
  2060.   cont = TRUE;
  2061.   classPtr = Nlm_GetClassPtr (a);
  2062.   while (classPtr != NULL && cont) {
  2063.     sendCh = classPtr->sendChar;
  2064.     if (sendCh != NULL) {
  2065.       sendCh (a, ch, savePort);
  2066.       cont = FALSE;
  2067.     } else {
  2068.       classPtr = classPtr->ancestor;
  2069.     }
  2070.   }
  2071. }
  2072.  
  2073. static Nlm_GraphiC Nlm_CheckThisLevel (Nlm_GraphiC a, Nlm_Char ch)
  2074.  
  2075. {
  2076.   Nlm_GraphiC  p;
  2077.   Nlm_GraphiC  q;
  2078.  
  2079.   q = NULL;
  2080.   p = a;
  2081.   while (p != NULL && q == NULL) {
  2082.     q = Nlm_DoGainFocus (p, ch, FALSE);
  2083.     p = Nlm_GetNext (p);
  2084.   }
  2085.   return q;
  2086. }
  2087.  
  2088. extern void Nlm_DoSendFocus (Nlm_GraphiC a, Nlm_Char ch)
  2089.  
  2090. {
  2091.   Nlm_GraphiC   cur;
  2092.   Nlm_GraphiC   nxt;
  2093.   Nlm_GraphiC   q;
  2094.  
  2095.   q = NULL;
  2096.   nxt = (Nlm_GraphiC) a;
  2097.   while (q == NULL && nxt != NULL) {
  2098.     cur = nxt;
  2099.     nxt = Nlm_GetParent (cur);
  2100.     if (nxt != NULL) {
  2101.       cur = Nlm_GetNext (cur);
  2102.     }
  2103.     q = Nlm_CheckThisLevel (cur, ch);
  2104.   }
  2105. }
  2106.  
  2107. extern void Nlm_DoAction (Nlm_GraphiC a)
  2108.  
  2109. {
  2110.   void             (*act) PROTO((Nlm_GraphiC));
  2111.   Nlm_GraphicData  gdata;
  2112.  
  2113.   if (a != NULL) {
  2114.     Nlm_GetGraphicData (a, &gdata);
  2115.     act = gdata.action;
  2116.     if (act != NULL) {
  2117.       act (a);
  2118.     }
  2119.   }
  2120. }
  2121.  
  2122. extern void Nlm_Show (Nlm_Handle a)
  2123.  
  2124. {
  2125.   Nlm_DoShow ((Nlm_GraphiC) a, TRUE, TRUE);
  2126. }
  2127.  
  2128. extern void Nlm_Hide (Nlm_Handle a)
  2129.  
  2130. {
  2131.   Nlm_DoHide ((Nlm_GraphiC) a, TRUE, TRUE);
  2132. }
  2133.  
  2134. extern void Nlm_Enable (Nlm_Handle a)
  2135.  
  2136. {
  2137.   Nlm_DoEnable ((Nlm_GraphiC) a, TRUE, TRUE);
  2138. }
  2139.  
  2140. extern void Nlm_Disable (Nlm_Handle a)
  2141.  
  2142. {
  2143.   Nlm_DoDisable ((Nlm_GraphiC) a, TRUE, TRUE);
  2144. }
  2145.  
  2146. extern Nlm_Handle Nlm_Remove (Nlm_Handle a)
  2147.  
  2148. {
  2149.   return Nlm_DoRemove ((Nlm_GraphiC) a, TRUE);
  2150. }
  2151.  
  2152. extern void Nlm_Reset (Nlm_Handle a)
  2153.  
  2154. {
  2155.   Nlm_DoReset ((Nlm_GraphiC) a, TRUE);
  2156. }
  2157.  
  2158. extern void Nlm_Select (Nlm_Handle a)
  2159.  
  2160. {
  2161.   Nlm_DoSelect ((Nlm_GraphiC) a, TRUE);
  2162. }
  2163.  
  2164. extern void Nlm_SetTitle (Nlm_Handle a, Nlm_CharPtr title)
  2165.  
  2166. {
  2167.   Nlm_DoSetTitle ((Nlm_GraphiC) a, 0, title, TRUE);
  2168. }
  2169.  
  2170. extern void Nlm_GetTitle (Nlm_Handle a, Nlm_CharPtr title, Nlm_sizeT maxsize)
  2171.  
  2172. {
  2173.   Nlm_DoGetTitle ((Nlm_GraphiC) a, 0, title, maxsize);
  2174. }
  2175.  
  2176. extern void Nlm_SetValue (Nlm_Handle a, Nlm_Int2 value)
  2177.  
  2178. {
  2179.   Nlm_DoSetValue ((Nlm_GraphiC) a, value, TRUE);
  2180. }
  2181.  
  2182. extern Nlm_Int2 Nlm_GetValue (Nlm_Handle a)
  2183.  
  2184. {
  2185.   return (Nlm_DoGetValue ((Nlm_GraphiC) a));
  2186. }
  2187.  
  2188. extern void Nlm_SetStatus (Nlm_Handle a, Nlm_Boolean status)
  2189.  
  2190. {
  2191.   Nlm_DoSetStatus ((Nlm_GraphiC) a, 0, status, TRUE);
  2192. }
  2193.  
  2194. extern Nlm_Boolean Nlm_GetStatus (Nlm_Handle a)
  2195.  
  2196. {
  2197.   return (Nlm_DoGetStatus ((Nlm_GraphiC) a, 0));
  2198. }
  2199.  
  2200. extern void Nlm_SetOffset (Nlm_Handle a, Nlm_Int2 horiz, Nlm_Int2 vert)
  2201.  
  2202. {
  2203.   Nlm_DoSetOffset ((Nlm_GraphiC) a, horiz, vert, TRUE);
  2204. }
  2205.  
  2206. extern void Nlm_GetOffset (Nlm_Handle a, Nlm_Int2Ptr horiz, Nlm_Int2Ptr vert)
  2207.  
  2208. {
  2209.   Nlm_DoGetOffset ((Nlm_GraphiC) a, horiz, vert);
  2210. }
  2211.  
  2212. extern void Nlm_SetPosition (Nlm_Handle a, Nlm_RectPtr r)
  2213.  
  2214. {
  2215.   Nlm_DoSetPosition ((Nlm_GraphiC) a, r, TRUE);
  2216. }
  2217.  
  2218. extern void Nlm_GetPosition (Nlm_Handle a, Nlm_RectPtr r)
  2219.  
  2220. {
  2221.   Nlm_DoGetPosition ((Nlm_GraphiC) a, r);
  2222. }
  2223.  
  2224. extern void Nlm_SetRange (Nlm_Handle a, Nlm_Int2 pgUp,
  2225.                           Nlm_Int2 pgDn, Nlm_Int2 max)
  2226.  
  2227. {
  2228.   Nlm_DoSetRange ((Nlm_GraphiC) a, pgUp, pgDn, max, TRUE);
  2229. }
  2230.  
  2231. extern void Nlm_SetItemTitle (Nlm_Handle a, Nlm_Int2 item, Nlm_CharPtr title)
  2232.  
  2233. {
  2234.   Nlm_DoSetTitle ((Nlm_GraphiC) a, item, title, TRUE);
  2235. }
  2236.  
  2237. extern void Nlm_GetItemTitle (Nlm_Handle a, Nlm_Int2 item, Nlm_CharPtr title, Nlm_sizeT maxsize)
  2238.  
  2239. {
  2240.   Nlm_DoGetTitle ((Nlm_GraphiC) a, item, title, maxsize);
  2241. }
  2242.  
  2243. extern void Nlm_SetItemStatus (Nlm_Handle a, Nlm_Int2 item, Nlm_Boolean status)
  2244.  
  2245. {
  2246.   Nlm_DoSetStatus ((Nlm_GraphiC) a, item, status, TRUE);
  2247. }
  2248.  
  2249. extern Nlm_Boolean Nlm_GetItemStatus (Nlm_Handle a, Nlm_Int2 item)
  2250.  
  2251. {
  2252.   return (Nlm_DoGetStatus ((Nlm_GraphiC) a, item));
  2253. }
  2254.  
  2255. extern Nlm_Int2 Nlm_GetNextItem (Nlm_Handle a, Nlm_Int2 prev)
  2256.  
  2257. {
  2258.   Nlm_GphPrcsPtr  classPtr;
  2259.   Nlm_Int2        (*cntitm) PROTO((Nlm_GraphiC));
  2260.   Nlm_Int2        count;
  2261.   Nlm_Boolean     (*gtsts) PROTO((Nlm_GraphiC, Nlm_Int2));
  2262.   Nlm_Boolean     found;
  2263.   Nlm_Int2        rsult;
  2264.  
  2265.   rsult = 0;
  2266.   if (a != NULL && prev >= 0) {
  2267.     classPtr = Nlm_GetClassPtr ((Nlm_GraphiC) a);
  2268.     if (classPtr != NULL) {
  2269.       cntitm = classPtr->countItems;
  2270.       gtsts = classPtr->getStatus;
  2271.       if (cntitm != NULL && gtsts != NULL) {
  2272.         count = cntitm ((Nlm_GraphiC) a);
  2273.         found = FALSE;
  2274.         while (prev < count && (! found)) {
  2275.           prev++;
  2276.           found = gtsts ((Nlm_GraphiC) a, prev);
  2277.         }
  2278.         if (found) {
  2279.           rsult = prev;
  2280.         }
  2281.       }
  2282.     }
  2283.   }
  2284.   return rsult;
  2285. }
  2286.  
  2287. extern void Nlm_ClearItemsInGroup (Nlm_GraphiC a, Nlm_GraphiC excpt, Nlm_Boolean savePort)
  2288.  
  2289. {
  2290.   Nlm_GraphiC  g;
  2291.  
  2292.   if (a != NULL) {
  2293.     g = Nlm_GetChild (a);
  2294.     while (g != NULL) {
  2295.       if (g != excpt) {
  2296.         Nlm_DoSetStatus (g, 0, FALSE, savePort);
  2297.       }
  2298.       g = Nlm_GetNext (g);
  2299.     }
  2300.   }
  2301. }
  2302.  
  2303. extern Nlm_Int2 Nlm_CountGroupItems (Nlm_GraphiC a)
  2304.  
  2305. {
  2306.   Nlm_GraphiC  g;
  2307.   Nlm_Int2     i;
  2308.  
  2309.   i = 0;
  2310.   if (a != NULL) {
  2311.     g = Nlm_GetChild (a);
  2312.     while (g != NULL) {
  2313.       i++;
  2314.       g = Nlm_GetNext (g);
  2315.     }
  2316.   }
  2317.   return i;
  2318. }
  2319.  
  2320. extern Nlm_GraphiC Nlm_LinkIn (Nlm_GraphiC a, Nlm_GraphiC prnt)
  2321.  
  2322. {
  2323.   Nlm_GraphiC  first;
  2324.   Nlm_GraphiC  g;
  2325.   Nlm_GphPtr   gp;
  2326.   Nlm_GraphiC  last;
  2327.   Nlm_GphPtr   lastp;
  2328.   Nlm_GraphiC  p;
  2329.   Nlm_GphPtr   prntp;
  2330.  
  2331.   if (prnt != NULL) {
  2332.     g = (Nlm_GraphiC) a;
  2333.     prntp = (Nlm_GphPtr) Nlm_HandLock (prnt);
  2334.     first = prntp->children;
  2335.     last = prntp->lastChild;
  2336.     Nlm_HandUnlock (prnt);
  2337.     if (last != NULL) {
  2338.       lastp = (Nlm_GphPtr) Nlm_HandLock (last);
  2339.       lastp->next = g;
  2340.       Nlm_HandUnlock (last);
  2341.       prntp = (Nlm_GphPtr) Nlm_HandLock (prnt);
  2342.       prntp->lastChild = g;
  2343.       Nlm_HandUnlock (prnt);
  2344.     } else if (first != NULL) {
  2345.       p = first;
  2346.       while (p != NULL) {
  2347.         last = p;
  2348.         p = Nlm_GetNext (p);
  2349.       }
  2350.       lastp = (Nlm_GphPtr) Nlm_HandLock (last);
  2351.       lastp->next = g;
  2352.       Nlm_HandUnlock (last);
  2353.       prntp = (Nlm_GphPtr) Nlm_HandLock (prnt);
  2354.       prntp->lastChild = g;
  2355.       Nlm_HandUnlock (prnt);
  2356.     } else {
  2357.       prntp = (Nlm_GphPtr) Nlm_HandLock (prnt);
  2358.       prntp->children = g;
  2359.       prntp->lastChild = g;
  2360.       Nlm_HandUnlock (prnt);
  2361.     }
  2362.     gp = (Nlm_GphPtr) Nlm_HandLock (g);
  2363.     gp->next = NULL;
  2364.     gp->parent = prnt;
  2365.     gp->children = NULL;
  2366.     gp->lastChild = NULL;
  2367.     Nlm_HandUnlock (g);
  2368.   }
  2369.   recentGraphic = NULL;
  2370.   recentBox = NULL;
  2371.   return a;
  2372. }
  2373.  
  2374. extern void Nlm_LoadAction (Nlm_GraphiC a, Nlm_ActnProc actnProc)
  2375.  
  2376. {
  2377.   Nlm_GraphicData  gdata;
  2378.  
  2379.   if (a != NULL) {
  2380.     Nlm_GetGraphicData (a, &gdata);
  2381.     gdata.action = actnProc;
  2382.     Nlm_SetGraphicData (a, &gdata);
  2383.   }
  2384. }
  2385.  
  2386. extern void Nlm_LoadGraphicData (Nlm_GraphiC a, Nlm_GraphiC nxt,
  2387.                                  Nlm_GraphiC prnt, Nlm_GraphiC chld,
  2388.                                  Nlm_GraphiC lstchd, Nlm_GphPrcs PNTR classPtr,
  2389.                                  Nlm_ActnProc actnProc, Nlm_RectPtr r,
  2390.                                  Nlm_Boolean enabl, Nlm_Boolean vis)
  2391.  
  2392. {
  2393.   Nlm_GphPtr  ptr;
  2394.  
  2395.   if (a != NULL) {
  2396.     ptr = (Nlm_GphPtr) Nlm_HandLock (a);
  2397.     ptr->next = nxt;
  2398.     ptr->parent = prnt;
  2399.     ptr->children = chld;
  2400.     ptr->lastChild = lstchd;
  2401.     ptr->classptr = classPtr;
  2402.     ptr->action = actnProc;
  2403.     if (r != NULL) {
  2404.       ptr->rect = *r;
  2405.     } else {
  2406.       Nlm_LoadRect (&(ptr->rect), 0, 0, 0, 0);
  2407.     }
  2408.     ptr->enabled = enabl;
  2409.     ptr->visible = vis;
  2410.     Nlm_HandUnlock (a);
  2411.     recentGraphic = NULL;
  2412.   }
  2413. }
  2414.  
  2415. extern void Nlm_LoadBoxData (Nlm_BoX a, Nlm_PoinT nxt,
  2416.                              Nlm_PoinT lmt, Nlm_PoinT rst,
  2417.                              Nlm_Int2 top, Nlm_Int2 ncol,
  2418.                              Nlm_Int2 xMrg, Nlm_Int2 yMrg,
  2419.                              Nlm_Int2 xSpc, Nlm_Int2 ySpc,
  2420.                              Nlm_Int2 wid, Nlm_Int2 hgt)
  2421.  
  2422. {
  2423.   Nlm_BoxPtr   bp;
  2424.   Nlm_BoxData  PNTR bptr;
  2425.  
  2426.   if (a != NULL) {
  2427.     bp = (Nlm_BoxPtr) Nlm_HandLock (a);
  2428.     bptr = &(bp->box);
  2429.     bptr->nextPoint = nxt;
  2430.     bptr->limitPoint = lmt;
  2431.     bptr->resetPoint = rst;
  2432.     bptr->topRow = top;
  2433.     bptr->nextCol = ncol;
  2434.     bptr->xMargin = xMrg;
  2435.     bptr->yMargin = yMrg;
  2436.     bptr->xSpacing = xSpc;
  2437.     bptr->ySpacing = ySpc;
  2438.     bptr->boxWidth = wid;
  2439.     bptr->boxHeight = hgt;
  2440.     Nlm_HandUnlock (a);
  2441.     recentBox = NULL;
  2442.   }
  2443. }
  2444.  
  2445. extern void Nlm_SetAction (Nlm_Handle a, Nlm_ActnProc actn)
  2446.  
  2447. {
  2448.   Nlm_GraphiC      g;
  2449.   Nlm_GraphicData  gdata;
  2450.  
  2451.   if (a != NULL) {
  2452.     g = (Nlm_GraphiC) a;
  2453.     if (g != NULL) {
  2454.       Nlm_GetGraphicData (g, &gdata);
  2455.       gdata.action = actn;
  2456.       Nlm_SetGraphicData (g, &gdata);
  2457.     }
  2458.   }
  2459. }
  2460.  
  2461. extern Nlm_GraphiC Nlm_CreateLink (Nlm_GraphiC prnt, Nlm_RectPtr r,
  2462.                                    Nlm_Int2 recordSize, Nlm_GphPrcs PNTR classPtr)
  2463.  
  2464. {
  2465.   Nlm_GraphiC  a;
  2466.   Nlm_GraphiC  rsult;
  2467.  
  2468.   rsult = NULL;
  2469.   a = NULL;
  2470.   if (prnt != NULL) {
  2471.     a = (Nlm_GraphiC) Nlm_HandNew (recordSize);
  2472.     if (a != NULL) {
  2473.       Nlm_LoadGraphicData (a, NULL, prnt, NULL, NULL, classPtr,
  2474.                            NULL, r, TRUE, FALSE);
  2475.       rsult = Nlm_DoLinkIn (a, prnt);
  2476.       if (rsult != NULL) {
  2477.         if (Nlm_nextIdNumber < 32767) {
  2478.           Nlm_nextIdNumber++;
  2479.         }
  2480.       } else {
  2481.         Nlm_HandFree (a);
  2482.       }
  2483.     }
  2484.   }
  2485.   return rsult;
  2486. }
  2487.  
  2488. extern void Nlm_RemoveLink (Nlm_GraphiC a)
  2489.  
  2490. {
  2491.   Nlm_GraphiC  first;
  2492.   Nlm_GraphiC  g;
  2493.   Nlm_GraphiC  n;
  2494.   Nlm_GraphiC  p;
  2495.   Nlm_GraphiC  prnt;
  2496.   Nlm_GphPtr   prntp;
  2497.   Nlm_GraphiC  q;
  2498.   Nlm_GphPtr   qp;
  2499.  
  2500.   if (a != NULL) {
  2501.     g = (Nlm_GraphiC) a;
  2502.     prnt = Nlm_GetParent (g);
  2503.     first = Nlm_GetChild (prnt);
  2504.     if (g == first) {
  2505.       n = Nlm_GetNext (g);
  2506.       prntp = (Nlm_GphPtr) Nlm_HandLock (prnt);
  2507.       prntp->children = n;
  2508.       if (prntp->lastChild == g) {
  2509.         prntp->lastChild = NULL;
  2510.       }
  2511.       Nlm_HandUnlock (prnt);
  2512.     } else {
  2513.       p = first;
  2514.       q = NULL; /* dgg: bug fix for when p==NULL*/
  2515.       while (p != NULL && p != g) {
  2516.         q = p;
  2517.         p = Nlm_GetNext (p);
  2518.       }
  2519.       if (q != NULL) {
  2520.         n = Nlm_GetNext (g);
  2521.         qp = (Nlm_GphPtr) Nlm_HandLock (q);
  2522.         qp->next = n;
  2523.         Nlm_HandUnlock (q);
  2524.       }
  2525.     }
  2526.     Nlm_HandFree (g);
  2527.   }
  2528.   recentGraphic = NULL;
  2529.   recentBox = NULL;
  2530. }
  2531.  
  2532. extern Nlm_GraphiC Nlm_FindItem (Nlm_GraphiC a, Nlm_Int2 item)
  2533.  
  2534. {
  2535.   Nlm_GraphiC  g;
  2536.  
  2537.   g = NULL;
  2538.   if (a != NULL && item > 0) {
  2539.     g = Nlm_GetChild (a);
  2540.     while (g != NULL && item > 1) {
  2541.       item--;
  2542.       g = Nlm_GetNext (g);
  2543.     }
  2544.   }
  2545.   return g;
  2546. }
  2547.  
  2548. extern Nlm_Int2 Nlm_GetItemIndex (Nlm_GraphiC a)
  2549.  
  2550. {
  2551.   Nlm_GraphiC  g;
  2552.   Nlm_Int2     index;
  2553.   Nlm_Int2     rsult;
  2554.  
  2555.   rsult = 0;
  2556.   if (a != NULL) {
  2557.     index = 1;
  2558.     g = Nlm_GetChild (a);
  2559.     while (g != NULL && g != a) {
  2560.       index++;
  2561.       g = Nlm_GetNext (g);
  2562.     }
  2563.     if (g == a) {
  2564.       rsult = index;
  2565.     } else {
  2566.       rsult = 0;
  2567.     }
  2568.   }
  2569.   return rsult;
  2570. }
  2571.  
  2572. extern Nlm_Boolean Nlm_GetAllParentsEnabled (Nlm_GraphiC a)
  2573.  
  2574. {
  2575.   Nlm_GraphiC  p;
  2576.  
  2577.   p = NULL;
  2578.   if (a != NULL) {
  2579.     p = Nlm_GetParent (a);
  2580.     while (p != NULL && Nlm_GetEnabled (p)) {
  2581.       p = Nlm_GetParent (p);
  2582.     }
  2583.   }
  2584.   return (Nlm_Boolean) (p == NULL);
  2585. }
  2586.  
  2587. extern Nlm_Boolean Nlm_AllParentsEnabled (Nlm_Handle a)
  2588.  
  2589. {
  2590.   return Nlm_GetAllParentsEnabled ((Nlm_GraphiC) a);
  2591. }
  2592.  
  2593. extern Nlm_Boolean Nlm_AllParentsButWindowVisible (Nlm_GraphiC a)
  2594.  
  2595. {
  2596.   Nlm_GraphiC  p;
  2597.  
  2598.   p = NULL;
  2599.   if (a != NULL) {
  2600.     p = Nlm_GetParent (a);
  2601.     while (p != NULL && Nlm_GetVisible (p)) {
  2602.       p = Nlm_GetParent (p);
  2603.     }
  2604.   }
  2605.   return (Nlm_Boolean) (p == NULL || Nlm_GetParent (p) == NULL);
  2606. }
  2607.  
  2608. extern Nlm_Boolean Nlm_GetAllParentsVisible (Nlm_GraphiC a)
  2609.  
  2610. {
  2611.   Nlm_GraphiC  p;
  2612.  
  2613.   p = NULL;
  2614.   if (a != NULL) {
  2615.     p = Nlm_GetParent (a);
  2616.     while (p != NULL && Nlm_GetVisible (p)) {
  2617.       p = Nlm_GetParent (p);
  2618.     }
  2619.   }
  2620.   return (Nlm_Boolean) (p == NULL);
  2621. }
  2622.  
  2623. extern Nlm_Boolean Nlm_AllParentsVisible (Nlm_Handle a)
  2624.  
  2625. {
  2626.   return Nlm_GetAllParentsVisible ((Nlm_GraphiC) a);
  2627. }
  2628.  
  2629. extern void Nlm_SetNext (Nlm_GraphiC a, Nlm_GraphiC nxt)
  2630.  
  2631. {
  2632.   Nlm_GraphicData  gdata;
  2633.  
  2634.   if (a != NULL) {
  2635.     Nlm_GetGraphicData (a, &gdata);
  2636.     gdata.next = nxt;
  2637.     Nlm_SetGraphicData (a, &gdata);
  2638.   }
  2639. }
  2640.  
  2641. extern Nlm_GraphiC Nlm_GetNext (Nlm_GraphiC a)
  2642.  
  2643. {
  2644.   Nlm_GraphicData  gdata;
  2645.   Nlm_GraphiC      rsult;
  2646.  
  2647.   rsult = NULL;
  2648.   if (a != NULL) {
  2649.     Nlm_GetGraphicData (a, &gdata);
  2650.     rsult = gdata.next;
  2651.   }
  2652.   return rsult;
  2653. }
  2654.  
  2655. extern void Nlm_SetParent (Nlm_GraphiC a, Nlm_GraphiC prnt)
  2656.  
  2657. {
  2658.   Nlm_GraphicData  gdata;
  2659.  
  2660.   if (a != NULL) {
  2661.     Nlm_GetGraphicData (a, &gdata);
  2662.     gdata.parent = prnt;
  2663.     Nlm_SetGraphicData (a, &gdata);
  2664.   }
  2665. }
  2666.  
  2667. extern Nlm_GraphiC Nlm_GetParent (Nlm_GraphiC a)
  2668.  
  2669. {
  2670.   Nlm_GraphicData  gdata;
  2671.   Nlm_GraphiC      rsult;
  2672.  
  2673.   rsult = NULL;
  2674.   if (a != NULL) {
  2675.     Nlm_GetGraphicData (a, &gdata);
  2676.     rsult = gdata.parent;
  2677.   }
  2678.   return rsult;
  2679. }
  2680.  
  2681. extern Nlm_Handle Nlm_Parent (Nlm_Handle a)
  2682.  
  2683. {
  2684.   return Nlm_GetParent ((Nlm_GraphiC) a);
  2685. }
  2686.  
  2687. extern void Nlm_SetChild (Nlm_GraphiC a, Nlm_GraphiC chld)
  2688.  
  2689. {
  2690.   Nlm_GraphicData  gdata;
  2691.  
  2692.   if (a != NULL) {
  2693.     Nlm_GetGraphicData (a, &gdata);
  2694.     gdata.children = chld;
  2695.     Nlm_SetGraphicData (a, &gdata);
  2696.   }
  2697. }
  2698.  
  2699. extern Nlm_GraphiC Nlm_GetChild (Nlm_GraphiC a)
  2700.  
  2701. {
  2702.   Nlm_GraphicData  gdata;
  2703.   Nlm_GraphiC      rsult;
  2704.  
  2705.   rsult = NULL;
  2706.   if (a != NULL) {
  2707.     Nlm_GetGraphicData (a, &gdata);
  2708.     rsult = gdata.children;
  2709.   }
  2710.   return rsult;
  2711. }
  2712.  
  2713. extern void Nlm_SetRect (Nlm_GraphiC a, Nlm_RectPtr r)
  2714.  
  2715. {
  2716.   Nlm_GraphicData  gdata;
  2717.  
  2718.   if (a != NULL && r != NULL) {
  2719.     Nlm_GetGraphicData (a, &gdata);
  2720.     gdata.rect = *r;
  2721.     Nlm_SetGraphicData (a, &gdata);
  2722.   }
  2723. }
  2724.  
  2725. extern void Nlm_GetRect (Nlm_GraphiC a, Nlm_RectPtr r)
  2726.  
  2727. {
  2728.   Nlm_GraphicData  gdata;
  2729.  
  2730.   if (a != NULL && r != NULL) {
  2731.     Nlm_GetGraphicData (a, &gdata);
  2732.     *r = gdata.rect;
  2733.   }
  2734. }
  2735.  
  2736. extern void Nlm_ObjectRect (Nlm_Handle a, Nlm_RectPtr r)
  2737.  
  2738. {
  2739.   Nlm_GetRect ((Nlm_GraphiC) a, r);
  2740. }
  2741.  
  2742. extern void Nlm_InvalObject (Nlm_Handle a)
  2743.  
  2744. {
  2745.   Nlm_RecT  r;
  2746.  
  2747.   if (a != NULL) {
  2748.     Nlm_GetRect ((Nlm_GraphiC) a, &r);
  2749.     Nlm_InsetRect (&r, -1, -1);
  2750.     Nlm_InvalRect (&r);
  2751.   }
  2752. }
  2753.  
  2754. extern void Nlm_SetEnabled (Nlm_GraphiC a, Nlm_Boolean enabld)
  2755.  
  2756. {
  2757.   Nlm_GraphicData  gdata;
  2758.  
  2759.   if (a != NULL) {
  2760.     Nlm_GetGraphicData (a, &gdata);
  2761.     gdata.enabled = enabld;
  2762.     Nlm_SetGraphicData (a, &gdata);
  2763.   }
  2764. }
  2765.  
  2766. extern Nlm_Boolean Nlm_GetEnabled (Nlm_GraphiC a)
  2767.  
  2768. {
  2769.   Nlm_GraphicData  gdata;
  2770.   Nlm_Boolean      rsult;
  2771.  
  2772.   rsult = FALSE;
  2773.   if (a != NULL) {
  2774.     Nlm_GetGraphicData (a, &gdata);
  2775.     rsult = gdata.enabled;
  2776.   }
  2777.   return rsult;
  2778. }
  2779.  
  2780. extern Nlm_Boolean Nlm_Enabled (Nlm_Handle a)
  2781.  
  2782. {
  2783.   return Nlm_GetEnabled ((Nlm_GraphiC) a);
  2784. }
  2785.  
  2786. extern void Nlm_SetVisible (Nlm_GraphiC a, Nlm_Boolean visibl)
  2787.  
  2788. {
  2789.   Nlm_GraphicData  gdata;
  2790.  
  2791.   if (a != NULL) {
  2792.     Nlm_GetGraphicData (a, &gdata);
  2793.     gdata.visible = visibl;
  2794.     Nlm_SetGraphicData (a, &gdata);
  2795.   }
  2796. }
  2797.  
  2798. extern Nlm_Boolean Nlm_GetVisible (Nlm_GraphiC a)
  2799.  
  2800. {
  2801.   Nlm_GraphicData  gdata;
  2802.   Nlm_Boolean      rsult;
  2803.  
  2804.   rsult = FALSE;
  2805.   if (a != NULL) {
  2806.     Nlm_GetGraphicData (a, &gdata);
  2807.     rsult = gdata.visible;
  2808.   }
  2809.   return rsult;
  2810. }
  2811.  
  2812. extern Nlm_Boolean Nlm_Visible (Nlm_Handle a)
  2813.  
  2814. {
  2815.   return Nlm_GetVisible ((Nlm_GraphiC) a);
  2816. }
  2817.  
  2818. extern void Nlm_SetGraphicData (Nlm_GraphiC a, Nlm_GraphicData PNTR gdata)
  2819.  
  2820. {
  2821.   Nlm_GphPtr  gp;
  2822.  
  2823.   if (a != NULL && gdata != NULL) {
  2824.     gp = (Nlm_GphPtr) Nlm_HandLock (a);
  2825.     *gp = *gdata;
  2826.     Nlm_HandUnlock (a);
  2827.     recentGraphic = a;
  2828.     recentGraphicData = *gdata;
  2829.   }
  2830. }
  2831.  
  2832. extern void Nlm_GetGraphicData (Nlm_GraphiC a, Nlm_GraphicData PNTR gdata)
  2833.  
  2834. {
  2835.   Nlm_GphPtr  gp;
  2836.  
  2837.   if (a != NULL && gdata != NULL) {
  2838.     if (a == recentGraphic && NLM_RISKY) {
  2839.       *gdata = recentGraphicData;
  2840.     } else {
  2841.       gp = (Nlm_GphPtr) Nlm_HandLock (a);
  2842.       *gdata = *gp;
  2843.       Nlm_HandUnlock (a);
  2844.       recentGraphic = a;
  2845.       recentGraphicData = *gdata;
  2846.     }
  2847.   }
  2848. }
  2849.  
  2850. extern void Nlm_SetBoxData (Nlm_BoX a, Nlm_BoxData PNTR bdata)
  2851.  
  2852. {
  2853.   Nlm_BoxPtr  bp;
  2854.  
  2855.   if (a != NULL && bdata != NULL) {
  2856.     bp = (Nlm_BoxPtr) Nlm_HandLock (a);
  2857.     bp->box = *bdata;
  2858.     Nlm_HandUnlock (a);
  2859.     recentBox = a;
  2860.     recentBoxData = *bdata;
  2861.   }
  2862. }
  2863.  
  2864. extern void Nlm_GetBoxData (Nlm_BoX a, Nlm_BoxData PNTR bdata)
  2865.  
  2866. {
  2867.   Nlm_BoxPtr  bp;
  2868.  
  2869.   if (a != NULL && bdata != NULL) {
  2870.     if (a == recentBox && NLM_RISKY) {
  2871.       *bdata = recentBoxData;
  2872.     } else {
  2873.       bp = (Nlm_BoxPtr) Nlm_HandLock (a);
  2874.       *bdata = bp->box;
  2875.       Nlm_HandUnlock (a);
  2876.       recentBox = a;
  2877.       recentBoxData = *bdata;
  2878.     }
  2879.   }
  2880. }
  2881.  
  2882. extern void Nlm_SetExtraData (Nlm_GraphiC a, Nlm_VoidPtr dptr,
  2883.                               Nlm_Int2 start, Nlm_Int2 extra)
  2884.  
  2885. {
  2886.   Nlm_BytePtr  dst;
  2887.   Nlm_GphPtr   gp;
  2888.   Nlm_BytePtr  src;
  2889.  
  2890.   if (a != NULL && dptr != NULL) {
  2891.     gp = (Nlm_GphPtr) Nlm_HandLock (a);
  2892.     dst = (Nlm_BytePtr) gp + start;
  2893.     src = (Nlm_BytePtr) dptr;
  2894.     while (extra > 0) {
  2895.       *dst = *src;
  2896.       dst++;
  2897.       src++;
  2898.       extra--;
  2899.     }
  2900.     Nlm_HandUnlock (a);
  2901.   }
  2902. }
  2903.  
  2904. extern void Nlm_GetExtraData (Nlm_GraphiC a, Nlm_VoidPtr dptr,
  2905.                               Nlm_Int2 start, Nlm_Int2 extra)
  2906.  
  2907. {
  2908.   Nlm_BytePtr  dst;
  2909.   Nlm_GphPtr   gp;
  2910.   Nlm_BytePtr  src;
  2911.  
  2912.   if (a != NULL && dptr != NULL) {
  2913.     gp = (Nlm_GphPtr) Nlm_HandLock (a);
  2914.     src = (Nlm_BytePtr) gp + start;
  2915.     dst = (Nlm_BytePtr) dptr;
  2916.     while (extra > 0) {
  2917.       *dst = *src;
  2918.       dst++;
  2919.       src++;
  2920.       extra--;
  2921.     }
  2922.     Nlm_HandUnlock (a);
  2923.   }
  2924. }
  2925.  
  2926. extern void Nlm_PointToolToPoinT (Nlm_PointTool src, Nlm_PointPtr dst)
  2927.  
  2928. {
  2929.   if (dst != NULL) {
  2930. #ifdef WIN_MAC
  2931.     dst->x = src.h;
  2932.     dst->y = src.v;
  2933. #endif
  2934. #ifdef WIN_MSWIN
  2935.     dst->x = (Nlm_Int2) src.x;
  2936.     dst->y = (Nlm_Int2) src.y;
  2937. #endif
  2938. #ifdef WIN_MOTIF
  2939.     dst->x = src.x;
  2940.     dst->y = src.y;
  2941. #endif
  2942.   }
  2943. }
  2944.  
  2945. extern void Nlm_PoinTToPointTool (Nlm_PoinT src, Nlm_PointTool PNTR dst)
  2946.  
  2947. {
  2948.   if (dst != NULL) {
  2949. #ifdef WIN_MAC
  2950.     dst->h = src.x;
  2951.     dst->v = src.y;
  2952. #endif
  2953. #ifdef WIN_MSWIN
  2954.     dst->x = src.x;
  2955.     dst->y = src.y;
  2956. #endif
  2957. #ifdef WIN_MOTIF
  2958.     dst->x = src.x;
  2959.     dst->y = src.y;
  2960. #endif
  2961.   }
  2962. }
  2963.  
  2964. extern void Nlm_RectToolToRecT (Nlm_RectTool PNTR src, Nlm_RectPtr dst)
  2965.  
  2966. {
  2967.   if (dst != NULL && src != NULL) {
  2968. #ifdef WIN_MAC
  2969.     dst->left = src->left;
  2970.     dst->top = src->top;
  2971.     dst->right = src->right;
  2972.     dst->bottom = src->bottom;
  2973. #endif
  2974. #ifdef WIN_MSWIN
  2975.     dst->left = (Nlm_Int2) src->left;
  2976.     dst->top = (Nlm_Int2) src->top;
  2977.     dst->right = (Nlm_Int2) src->right;
  2978.     dst->bottom = (Nlm_Int2) src->bottom;
  2979. #endif
  2980. #ifdef WIN_MOTIF
  2981.     dst->left = src->x;
  2982.     dst->top = src->y;
  2983.     dst->right = src->x + src->width;
  2984.     dst->bottom = src->y + src->height;
  2985. #endif
  2986.   }
  2987. }
  2988.  
  2989. extern void Nlm_RecTToRectTool (Nlm_RectPtr src, Nlm_RectTool PNTR dst)
  2990.  
  2991. {
  2992.   if (dst != NULL && src != NULL) {
  2993. #ifdef WIN_MAC
  2994.     dst->left = MIN (src->left, src->right);
  2995.     dst->top = MIN (src->top, src->bottom);
  2996.     dst->right = MAX (src->left, src->right);
  2997.     dst->bottom = MAX (src->top, src->bottom);
  2998. #endif
  2999. #ifdef WIN_MSWIN
  3000.     dst->left = MIN (src->left, src->right);
  3001.     dst->top = MIN (src->top, src->bottom);
  3002.     dst->right = MAX (src->left, src->right);
  3003.     dst->bottom = MAX (src->top, src->bottom);
  3004. #endif
  3005. #ifdef WIN_MOTIF
  3006.     dst->x = MIN (src->left, src->right);
  3007.     dst->y = MIN (src->top, src->bottom);
  3008.     dst->width = ABS (src->right - src->left);
  3009.     dst->height = ABS (src->bottom - src->top);
  3010. #endif
  3011.   }
  3012. }
  3013.  
  3014. extern void Nlm_LocalToGlobal (Nlm_PointPtr pt)
  3015.  
  3016. {
  3017. #ifdef WIN_MAC
  3018.   Nlm_PointTool  ptool;
  3019.  
  3020.   if (pt != NULL) {
  3021.     Nlm_PoinTToPointTool (*pt, &ptool);
  3022.     LocalToGlobal (&ptool);
  3023.     Nlm_PointToolToPoinT (ptool, pt);
  3024.   }
  3025. #endif
  3026. #ifdef WIN_MSWIN
  3027.   Nlm_PointTool  ptool;
  3028.  
  3029.   if (pt != NULL && Nlm_currentHWnd != NULL) {
  3030.     Nlm_PoinTToPointTool (*pt, &ptool);
  3031.     ClientToScreen (Nlm_currentHWnd, &ptool);
  3032.     Nlm_PointToolToPoinT (ptool, pt);
  3033.   }
  3034. #endif
  3035. #ifdef WIN_MOTIF
  3036. #endif
  3037. }
  3038.  
  3039. extern void Nlm_GlobalToLocal (Nlm_PointPtr pt)
  3040.  
  3041. {
  3042. #ifdef WIN_MAC
  3043.   Nlm_PointTool  ptool;
  3044.  
  3045.   if (pt != NULL) {
  3046.     Nlm_PoinTToPointTool (*pt, &ptool);
  3047.     GlobalToLocal (&ptool);
  3048.     Nlm_PointToolToPoinT (ptool, pt);
  3049.   }
  3050. #endif
  3051. #ifdef WIN_MSWIN
  3052.   Nlm_PointTool  ptool;
  3053.  
  3054.   if (pt != NULL && Nlm_currentHWnd != NULL) {
  3055.     Nlm_PoinTToPointTool (*pt, &ptool);
  3056.     ScreenToClient (Nlm_currentHWnd, &ptool);
  3057.     Nlm_PointToolToPoinT (ptool, pt);
  3058.   }
  3059. #endif
  3060. #ifdef WIN_MOTIF
  3061. #endif
  3062. }
  3063.  
  3064. #ifdef OS_MAC
  3065. extern void Nlm_CtoPstr (Nlm_CharPtr str)
  3066.  
  3067. {
  3068. #if defined(COMP_MPW) || defined(COMP_CODEWAR)
  3069.     c2pstr ((char *) str);
  3070. #else
  3071. #ifdef COMP_THINKC
  3072.     CtoPstr ((char *) str);
  3073. #endif
  3074. #endif
  3075. }
  3076.  
  3077. extern void Nlm_PtoCstr (Nlm_CharPtr str)
  3078.  
  3079. {
  3080. #if defined(COMP_MPW) || defined(COMP_CODEWAR)
  3081.   p2cstr ((StringPtr) str);
  3082. #else
  3083. #ifdef COMP_THINKC
  3084.   PtoCstr ((StringPtr) str);
  3085. #endif
  3086. #endif
  3087. }
  3088. #endif
  3089.  
  3090. #ifdef WIN_MSWIN
  3091. extern Nlm_Boolean Nlm_VibrantDisabled (void)
  3092.  
  3093. {
  3094.   if (Nlm_GetAppProperty("disable_vibrant") != NULL) {
  3095.     disabled_count++;
  3096.     return TRUE;
  3097.   }
  3098.   return FALSE;
  3099. }
  3100. #endif
  3101.  
  3102. #ifdef WIN_MSWIN
  3103. static void Nlm_SetupPrinterDeviceContext (HDC prHDC)
  3104.  
  3105. {
  3106.   HDC         screenDC;
  3107.   HWND        screenHwnd;
  3108.   /*
  3109.   TEXTMETRIC  textMetrics1;
  3110.   TEXTMETRIC  textMetrics2;
  3111.   */
  3112.  
  3113.   if (prHDC != NULL) {
  3114.     Nlm_SelectFont (Nlm_programFont);
  3115.     /*
  3116.     GetTextMetrics (Nlm_currentHDC, &textMetrics1);
  3117.     */
  3118.     Nlm_SetPort ((HWND) NULL, (HDC) prHDC);
  3119.     /*
  3120.     GetTextMetrics (prHDC, &textMetrics2);
  3121.     */
  3122.     SetMapMode (prHDC, MM_ANISOTROPIC);
  3123.     screenHwnd = GetDesktopWindow ();
  3124.     screenDC = GetDC (screenHwnd);
  3125.     SetWindowExtEx (prHDC, GetDeviceCaps (screenDC, LOGPIXELSX),
  3126.                     GetDeviceCaps (screenDC, LOGPIXELSY), NULL);
  3127.     SetViewportExtEx (prHDC, GetDeviceCaps (prHDC, LOGPIXELSX),
  3128.                       GetDeviceCaps (prHDC, LOGPIXELSY), NULL);
  3129.     ReleaseDC (screenHwnd, screenDC);
  3130.     /*
  3131.     SetWindowExtEx (prHDC, textMetrics1.tmAveCharWidth,
  3132.                     textMetrics1.tmHeight, NULL);
  3133.     SetViewportExtEx (prHDC, textMetrics2.tmAveCharWidth,
  3134.                     textMetrics2.tmHeight, NULL);
  3135.     */
  3136.   }
  3137. }
  3138. #endif
  3139.  
  3140. extern Nlm_WindoW Nlm_StartPrinting (void)
  3141.  
  3142. {
  3143.   Nlm_WindoW  w;
  3144. #ifdef WIN_MSWIN
  3145.   DWORD       commdlgerr;
  3146.   DOCINFO     di;
  3147.   char        docName [256];
  3148. #endif
  3149.  
  3150.   w = Nlm_CurrentWindow ();
  3151. #ifdef WIN_MAC
  3152.   PrOpen ();
  3153.   if (prHdl == NULL) {
  3154.     prHdl = (THPrint) Nlm_HandNew (sizeof (TPrint));
  3155.     if (prHdl != NULL) {
  3156.       PrintDefault (prHdl);
  3157.       prerr = PrError ();
  3158.       if (prerr != noErr) {
  3159.         Nlm_Message (MSG_ERROR, "PrintDefault error %d", prerr);
  3160.       }
  3161.       if (! PrStlDialog (prHdl)) {
  3162.         prHdl = (THPrint) Nlm_HandFree (prHdl);
  3163.         w = NULL;
  3164.       }
  3165.     } else {
  3166.       Nlm_Message (MSG_ERROR, "Unable to create print handle");
  3167.     }
  3168.   }
  3169.   if (prHdl != NULL) {
  3170.     if (PrJobDialog (prHdl)) {
  3171.       prPort = PrOpenDoc (prHdl, NULL, NULL);
  3172.       Nlm_SetPort ((GrafPtr) prPort);
  3173.       prerr = PrError ();
  3174.       if (prerr != noErr) {
  3175.         Nlm_Message (MSG_ERROR, "PrOpenDoc error %d", prerr);
  3176.       } else {
  3177.         Nlm_nowPrinting = TRUE;
  3178.       }
  3179.     } else {
  3180.       w = NULL;
  3181.     }
  3182.   } else {
  3183.     w = NULL;
  3184.   }
  3185. #endif
  3186. #ifdef WIN_MSWIN
  3187.   abortPrint = FALSE;
  3188.   memset (&pd, 0, sizeof (PRINTDLG));
  3189.   pd.lStructSize = sizeof (PRINTDLG);
  3190.   pd.hwndOwner = Nlm_currentHWnd;
  3191.   pd.Flags = PD_RETURNDC;
  3192.   if (PrintDlg (&pd) != 0) {
  3193.     hPr = pd.hDC;
  3194.     if (hPr != NULL) {
  3195.       Nlm_SetupPrinterDeviceContext (hPr);
  3196.       Nlm_StringCpy (docName, "Vibrant");
  3197.       di.cbSize = sizeof (DOCINFO);
  3198.       di.lpszDocName = (LPCSTR) docName;
  3199.       di.lpszOutput = NULL;
  3200.       prerr = StartDoc (hPr, &di);
  3201.       if (prerr < 1) {
  3202.         abortPrint = TRUE;
  3203.         Nlm_Message (MSG_ERROR, "StartDoc error %d", prerr);
  3204.         w = NULL;
  3205.       } else {
  3206.         Nlm_nowPrinting = TRUE;
  3207.       }
  3208.     } else {
  3209.       commdlgerr = CommDlgExtendedError ();
  3210.       Nlm_Message (MSG_ERROR, "Unable to create print context, error %ul", (long) commdlgerr);
  3211.       w = NULL;
  3212.     }
  3213.   } else {
  3214.     w = NULL;
  3215.   }
  3216. #endif
  3217. #ifdef WIN_MOTIF
  3218.   w = NULL;
  3219. #endif
  3220.   return w;
  3221. }
  3222.  
  3223. extern void Nlm_EndPrinting (Nlm_WindoW w)
  3224.  
  3225. {
  3226. #ifdef WIN_MAC
  3227.   TPrStatus  prStat;
  3228. #endif
  3229.  
  3230.   Nlm_nowPrinting = FALSE;
  3231. #ifdef WIN_MAC
  3232.   if (w != NULL) {
  3233.     PrCloseDoc (prPort);
  3234.     prerr = PrError ();
  3235.     if (prerr != noErr) {
  3236.       Nlm_Message (MSG_ERROR, "PrCloseDoc error %d", prerr);
  3237.     }
  3238.     PrPicFile (prHdl, 0L, 0L, 0L, &prStat);
  3239.     prerr = PrError ();
  3240.     if (prerr != noErr) {
  3241.       Nlm_Message (MSG_ERROR, "PrPicFile error %d", prerr);
  3242.     }
  3243.     prPort = NULL;
  3244.     Nlm_UseWindow (w);
  3245.   }
  3246.   PrClose ();
  3247. #endif
  3248. #ifdef WIN_MSWIN
  3249.   if (w != NULL) {
  3250.     if (hPr != NULL) {
  3251.       if (! abortPrint) {
  3252.         prerr = EndDoc (hPr);
  3253.         if (prerr < 0) {
  3254.           Nlm_Message (MSG_ERROR, "EndDoc error %d", prerr);
  3255.         }
  3256.       }
  3257.       DeleteDC (hPr);
  3258.       if (pd.hDevMode != NULL) {
  3259.         GlobalFree (pd.hDevMode);
  3260.       }
  3261.       if (pd.hDevNames != NULL) {
  3262.         GlobalFree (pd.hDevNames);
  3263.       }
  3264.     }
  3265.     Nlm_UseWindow (w);
  3266.   }
  3267. #endif
  3268. #ifdef WIN_MOTIF
  3269. #endif
  3270. }
  3271.  
  3272. extern Nlm_Boolean Nlm_PrintingRect (Nlm_RectPtr rpt)
  3273.  
  3274. {
  3275.   Nlm_Boolean   rsult;
  3276. #ifdef WIN_MAC
  3277.   TPPrint       prPtr;
  3278.   Nlm_RectTool  rtool;
  3279. #endif
  3280. #ifdef WIN_MSWIN
  3281.   POINT         physPageSize;
  3282.   POINT         pixelsPerInch;
  3283.   Nlm_PoinT     pt;
  3284. #endif
  3285.  
  3286.   rsult = TRUE;
  3287.   if (rpt != NULL) {
  3288.     Nlm_LoadRect (rpt, 0, 0, 0, 0);
  3289. #ifdef WIN_MAC
  3290.     if (prHdl != NULL) {
  3291.       prPtr = (TPPrint) Nlm_HandLock (prHdl);
  3292.       if (prPtr != NULL) {
  3293.         rtool = prPtr->prInfo.rPage;
  3294.         Nlm_RectToolToRecT (&rtool, rpt);
  3295.         Nlm_InsetRect (rpt, 10, 10);
  3296.       } else {
  3297.         rsult = FALSE;
  3298.       }
  3299.       Nlm_HandUnlock (prHdl);
  3300.     } else {
  3301.       rsult = FALSE;
  3302.     }
  3303. #endif
  3304. #ifdef WIN_MSWIN
  3305.     if (hPr != NULL) {
  3306.       physPageSize.x = GetDeviceCaps (hPr, HORZRES);
  3307.       physPageSize.y = GetDeviceCaps (hPr, VERTRES);
  3308.       DPtoLP (hPr, &physPageSize, 1);
  3309.       Nlm_PointToolToPoinT (physPageSize, &pt);
  3310.       rpt->right = pt.x;
  3311.       rpt->bottom = pt.y;
  3312.       pixelsPerInch.x = GetDeviceCaps (hPr, LOGPIXELSX);
  3313.       pixelsPerInch.y = GetDeviceCaps (hPr, LOGPIXELSY);
  3314.       DPtoLP (hPr, &pixelsPerInch, 1);
  3315.       Nlm_InsetRect (rpt, pixelsPerInch.x / 2, pixelsPerInch.y / 2);
  3316.     } else {
  3317.       rsult = FALSE;
  3318.     }
  3319. #endif
  3320. #ifdef WIN_MOTIF
  3321.     rsult = FALSE;
  3322. #endif
  3323.   }
  3324.   return rsult;
  3325. }
  3326.  
  3327. extern Nlm_Boolean Nlm_StartPage (void)
  3328.  
  3329. {
  3330.   Nlm_Boolean  rsult;
  3331.  
  3332.   rsult = TRUE;
  3333. #ifdef WIN_MAC
  3334.   if (prPort != NULL) {
  3335.     PrOpenPage (prPort, NULL);
  3336.     prerr = PrError ();
  3337.     if (prerr != noErr) {
  3338.       Nlm_Message (MSG_ERROR, "PrOpenPage error %d", prerr);
  3339.       rsult = FALSE;
  3340.     }
  3341.   } else {
  3342.     rsult = FALSE;
  3343.   }
  3344. #endif
  3345. #ifdef WIN_MSWIN
  3346.   if (hPr != NULL) {
  3347.     Nlm_SetupPrinterDeviceContext (hPr);
  3348.     prerr = StartPage (hPr);
  3349.     if (prerr < 0) {
  3350.       Nlm_Message (MSG_ERROR, "StartPage error %d", prerr);
  3351.       rsult = FALSE;
  3352.     }
  3353.     Nlm_SetPort ((HWND) NULL, (HDC) hPr);
  3354.   }
  3355. #endif
  3356. #ifdef WIN_MOTIF
  3357.   rsult = FALSE;
  3358. #endif
  3359.   return rsult;
  3360. }
  3361.  
  3362. extern Nlm_Boolean Nlm_EndPage (void)
  3363.  
  3364. {
  3365.   Nlm_Boolean  rsult;
  3366.  
  3367.   rsult = TRUE;
  3368. #ifdef WIN_MAC
  3369.   if (prPort != NULL) {
  3370.     PrClosePage (prPort);
  3371.     prerr = PrError ();
  3372.     if (prerr != noErr) {
  3373.       Nlm_Message (MSG_ERROR, "PrClosePage error %d", prerr);
  3374.       rsult = FALSE;
  3375.     }
  3376.   } else {
  3377.     rsult = FALSE;
  3378.   }
  3379. #endif
  3380. #ifdef WIN_MSWIN
  3381.   if (hPr != NULL) {
  3382.     prerr = EndPage (hPr);
  3383.     if (prerr < 0) {
  3384.       abortPrint = TRUE;
  3385.       Nlm_Message (MSG_ERROR, "EndPage error %d", prerr);
  3386.       rsult = FALSE;
  3387.     }
  3388.   } else {
  3389.     rsult = FALSE;
  3390.   }
  3391. #endif
  3392. #ifdef WIN_MOTIF
  3393.   rsult = FALSE;
  3394. #endif
  3395.   return rsult;
  3396. }
  3397.  
  3398. #ifdef WIN_MAC
  3399. static OSType Nlm_GetOSType (Nlm_CharPtr str, OSType dfault)
  3400.  
  3401. {
  3402.   OSType  rsult;
  3403.  
  3404.   rsult = dfault;
  3405.   if (str != NULL && str [0] != '\0') {
  3406.     rsult = *(OSType*) str;
  3407.   }
  3408.   return rsult;
  3409. }
  3410.  
  3411. static void Nlm_GetFilePath (Nlm_Int2 currentVol, Nlm_CharPtr path, Nlm_sizeT maxsize)
  3412.  
  3413. {
  3414.   WDPBRec     block;
  3415.   Nlm_Char    directory [256];
  3416.   Nlm_Int4    dirID;
  3417.   OSErr       err;
  3418.   CInfoPBRec  params;
  3419.   Nlm_Char    temp [256];
  3420.   Nlm_Int2    vRefNum;
  3421.  
  3422.   block.ioNamePtr = NULL;
  3423.   block.ioVRefNum = currentVol;
  3424.   block.ioWDIndex = 0;
  3425.   block.ioWDProcID = 0;
  3426.   PBGetWDInfo (&block, FALSE);
  3427.   dirID = block.ioWDDirID;
  3428.   vRefNum = block.ioWDVRefNum;
  3429.   temp [0] = '\0';
  3430.   params.dirInfo.ioNamePtr = (StringPtr) directory;
  3431.   params.dirInfo.ioDrParID = dirID;
  3432.   do {
  3433.     params.dirInfo.ioVRefNum = vRefNum;
  3434.     params.dirInfo.ioFDirIndex = -1;
  3435.     params.dirInfo.ioDrDirID = params.dirInfo.ioDrParID;
  3436.     err = PBGetCatInfo (¶ms, FALSE);
  3437.     Nlm_PtoCstr (directory);
  3438.     Nlm_StrngCat (directory, ":", sizeof (directory));
  3439.     Nlm_StrngCat (directory, temp, sizeof (directory));
  3440.     Nlm_StrngCpy (temp, directory, sizeof (temp));
  3441.   } while (params.dirInfo.ioDrDirID != fsRtDirID);
  3442.   Nlm_StringNCpy (path, temp, maxsize);
  3443. }
  3444. #endif
  3445.  
  3446. #ifdef WIN_MOTIF
  3447. static void Nlm_CreateFileDialogShell (void)
  3448.  
  3449. {
  3450.   Cardinal  n;
  3451.   Arg       wargs [15];
  3452.  
  3453.   if (Nlm_fileDialogShell == NULL) {
  3454.     n = 0;
  3455.     XtSetArg (wargs[n], XmNdefaultFontList, Nlm_XfontList); n++;
  3456.     XtSetArg (wargs[n], XmNdeleteResponse, XmDO_NOTHING); n++;
  3457.     Nlm_fileDialogShell = XtAppCreateShell ((String) NULL, (String) "Vibrant",
  3458.                                             applicationShellWidgetClass,
  3459.                                             Nlm_currentXDisplay, wargs, n);
  3460.   }
  3461. }
  3462.  
  3463. static void Nlm_FileCancelCallback (Widget fs, XtPointer client_data, XtPointer call_data)
  3464.  
  3465. {
  3466.   fileBoxUp = FALSE;
  3467.   fileBoxRsult = FALSE;
  3468. }
  3469.  
  3470. static void Nlm_FileOkCallback (Widget fs, XtPointer client_data, XtPointer call_data)
  3471.  
  3472. {
  3473.   XmFileSelectionBoxCallbackStruct  *cbs;
  3474.   char                              *filename;
  3475.  
  3476.   cbs = (XmFileSelectionBoxCallbackStruct *) call_data;
  3477.   fileBoxUp = FALSE;
  3478.   if (! XmStringGetLtoR (cbs->value, XmSTRING_DEFAULT_CHARSET, &filename)) {
  3479.     return;
  3480.   }
  3481.   if (! *filename) {
  3482.     XtFree (filename);
  3483.     return;
  3484.   }
  3485.   Nlm_StringNCpy (filePath, filename, sizeof (filePath));
  3486.   XtFree (filename);
  3487.   fileBoxRsult = TRUE;
  3488. }
  3489.  
  3490. static void Nlm_FileNoMatchCallback (Widget fs, XtPointer client_data, XtPointer call_data)
  3491.  
  3492. {
  3493.   fileBoxUp = FALSE;
  3494.   fileBoxRsult = FALSE;
  3495. }
  3496.  
  3497. static void Nlm_FileMapCallback (Widget fs, XtPointer client_data, XtPointer call_data)
  3498.  
  3499. {
  3500.   Position   x, y;
  3501.   Dimension  w, h;
  3502.  
  3503.   XtVaGetValues (fs, XmNwidth, &w, XmNheight, &h, NULL);
  3504.   x = (Position) (Nlm_screenRect.right - w) / (Position) 2;
  3505.   y = (Position) (Nlm_screenRect.bottom - h) / (Position) 3;
  3506.   XtVaSetValues (fs, XmNx, x, XmNy, y, NULL);
  3507. }
  3508. #endif
  3509.  
  3510. extern Nlm_Boolean Nlm_GetInputFileName (Nlm_CharPtr fileName, Nlm_sizeT maxsize,
  3511.                                          Nlm_CharPtr extType, Nlm_CharPtr macType)
  3512.  
  3513. {
  3514. #ifdef WIN_MAC
  3515.   Nlm_Char       currentFileName [64];
  3516.   Nlm_Char       currentPath [256];
  3517.   SFTypeList     fTypeList;
  3518.   Nlm_Int2       i;
  3519.   Nlm_Int2       lengthTypes;
  3520.   Nlm_Int2       numTypes;
  3521.   Nlm_PointTool  ptool;
  3522.   Nlm_RecT       r;
  3523.   SFReply        reply;
  3524.   Nlm_Boolean    rsult;
  3525.   Nlm_RectTool   rtool;
  3526.   GrafPtr        tempPort;
  3527.   PenState       state;
  3528.   Nlm_Char       str [5];
  3529.   Nlm_PoinT      where;
  3530.  
  3531.   where.x = 90;
  3532.   where.y = 100;
  3533.   lengthTypes = sizeof (fileTypes);
  3534.   for (i = 0; i < lengthTypes; i++) {
  3535.     fileTypes [i] = '\0';
  3536.   }
  3537. #ifdef DCLAP
  3538.     /* allow several types in this list! */
  3539.   if (macType != NULL && macType [0] != '\0') {
  3540.     Nlm_StringNCpy (fileTypes, macType, lengthTypes);
  3541.     /*fileTypes [lengthTypes-1] = '\0';*/
  3542.   }
  3543. #else
  3544.   if (macType != NULL && macType [0] != '\0') {
  3545.     Nlm_StringNCpy (fileTypes, macType, 6);
  3546.     fileTypes [4] = '\0';
  3547.   }
  3548. #endif
  3549.   if (fileTypes [0] != '\0') {
  3550.     numTypes = 0;
  3551.     i = 0;
  3552.     while (numTypes < 4 && i < lengthTypes) {
  3553.       Nlm_StrngSeg (str, fileTypes, i, 4, sizeof (str));
  3554.       fTypeList [numTypes] = Nlm_GetOSType (str, '    ');
  3555.       numTypes++;
  3556.       i += 4;
  3557.     }
  3558.   } else {
  3559.     numTypes = -1;
  3560.   }
  3561.   GetPenState (&state);
  3562.   GetPort (&tempPort);
  3563.   Nlm_PoinTToPointTool (where, &ptool);
  3564.   SFGetFile (ptool, NULL, NULL, numTypes, fTypeList, NULL, &reply);
  3565.   SetPort (tempPort);
  3566.   SetPenState (&state);
  3567.   Nlm_GetRect ((Nlm_GraphiC) Nlm_desktopWindow, &r);
  3568.   Nlm_RecTToRectTool (&r, &rtool);
  3569.   ClipRect (&rtool);
  3570.   if (reply.good != 0 && fileName != NULL) {
  3571.     Nlm_StringNCpy (currentFileName, (Nlm_CharPtr) &(reply.fName),
  3572.                     sizeof (currentFileName));
  3573.     Nlm_PtoCstr (currentFileName);
  3574.     Nlm_GetFilePath (reply.vRefNum, currentPath, sizeof (currentPath));
  3575.     Nlm_StringNCat (currentPath, currentFileName,
  3576.                     sizeof (currentPath) - Nlm_StringLen (currentPath));
  3577.     Nlm_StringNCpy (fileName, currentPath, maxsize);
  3578.     rsult = TRUE;
  3579.   } else {
  3580.     rsult = FALSE;
  3581.   }
  3582.   Nlm_Update ();
  3583.   return rsult;
  3584. #endif
  3585. #ifdef WIN_MSWIN
  3586.   char  szDirName [256];
  3587.   char  szFile [256];
  3588.   char  szFileTitle [256];
  3589.   UINT  i;
  3590.   UINT  cbString;
  3591.   char  chReplace;
  3592.   char  szFilter [256];
  3593.   char  *lastSlash;
  3594.  
  3595.   GetModuleFileName (Nlm_currentHInst, szDirName, sizeof (szDirName));
  3596.   lastSlash = strrchr (szDirName, DIRDELIMCHR);
  3597.   if (lastSlash != NULL) {
  3598.     lastSlash [1] = '\0';
  3599.   }
  3600.   szFile [0] = '\0';
  3601.   if (extType != NULL && extType [0] != '\0') {
  3602.     Nlm_StringCpy (szFilter, "Filtered Files (*");
  3603.     if (extType [0] != '.') {
  3604.       Nlm_StringCat (szFilter, ".");
  3605.     }
  3606.     Nlm_StringNCat (szFilter, extType, 5);
  3607.     Nlm_StringCat (szFilter, ")|*");
  3608.     if (extType [0] != '.') {
  3609.       Nlm_StringCat (szFilter, ".");
  3610.     }
  3611.     Nlm_StringNCat (szFilter, extType, 5);
  3612.     Nlm_StringCat (szFilter, "|");
  3613.   } else {
  3614.     Nlm_StringCpy (szFilter, "All Files (*.*)|*.*|");
  3615.   }
  3616.   cbString = (UINT) Nlm_StringLen (szFilter);
  3617.   chReplace = szFilter [cbString - 1];
  3618.   for (i = 0; szFilter [i] != '\0'; i++) {
  3619.     if (szFilter [i] == chReplace) {
  3620.       szFilter [i] = '\0';
  3621.     }
  3622.   }
  3623.   memset (&ofn, 0, sizeof (OPENFILENAME));
  3624.   ofn.lStructSize = sizeof (OPENFILENAME);
  3625.   ofn.hwndOwner = Nlm_currentHWnd;
  3626.   ofn.lpstrFilter = szFilter;
  3627.   ofn.nFilterIndex = 1;
  3628.   ofn.lpstrFile = szFile;
  3629.   ofn.nMaxFile = sizeof (szFile);
  3630.   ofn.lpstrFileTitle = szFileTitle;
  3631.   ofn.nMaxFileTitle = sizeof (szFileTitle);
  3632.   ofn.lpstrInitialDir = szDirName;
  3633.   ofn.Flags = OFN_SHOWHELP | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
  3634.   if (GetOpenFileName (&ofn) && fileName != NULL) {
  3635.     Nlm_StringNCpy (fileName, ofn.lpstrFile, maxsize);
  3636.     AnsiToOemBuff (fileName, fileName, maxsize);
  3637.     return TRUE;
  3638.   } else {
  3639.     return FALSE;
  3640.   }
  3641. #endif
  3642. #ifdef WIN_MOTIF
  3643.   XmString  dirmask;
  3644.   char      *lastSlash;
  3645.   char      str [256];
  3646.   char      *text;
  3647.   Widget    txt;
  3648.  
  3649.   Nlm_CreateFileDialogShell ();
  3650.   if (Nlm_fileDialogShell != NULL && fileName != NULL) {
  3651.     if (fileDialog == NULL) {
  3652.       fileDialog = XmCreateFileSelectionDialog (Nlm_fileDialogShell,
  3653.                                                 (String) "file_selection", NULL, 0);
  3654.       XtAddCallback (fileDialog, XmNcancelCallback, Nlm_FileCancelCallback, NULL);
  3655.       XtAddCallback (fileDialog, XmNokCallback, Nlm_FileOkCallback, NULL);
  3656.       XtAddCallback (fileDialog, XmNnoMatchCallback, Nlm_FileNoMatchCallback, NULL);
  3657.       XtAddCallback (fileDialog, XmNmapCallback, Nlm_FileMapCallback, NULL);
  3658.       XtVaSetValues (fileDialog, XmNdefaultPosition, FALSE,
  3659.                      XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL, NULL);
  3660.     }
  3661.     if (fileDialog != NULL) {
  3662.       txt = XmFileSelectionBoxGetChild (fileDialog, XmDIALOG_FILTER_TEXT);
  3663.       text = XmTextGetString (txt);
  3664.       Nlm_StringNCpy (str, text, sizeof (str) - 1);
  3665.       lastSlash = Nlm_StringRChr (str, DIRDELIMCHR);
  3666.       if (lastSlash != NULL) {
  3667.         lastSlash [1] = '\0';
  3668.       } else {
  3669.         lastSlash = &(str [Nlm_StringLen (str) - 1]);
  3670.       }
  3671.       if (extType != NULL && extType [0] != '\0') {
  3672.         Nlm_StringCat (str, "*");
  3673.         if (extType [0] != '.') {
  3674.           Nlm_StringCat (str, ".");
  3675.         }
  3676.         Nlm_StringNCat (str, extType, 5);
  3677.         dirmask = XmStringCreateLtoR (str, XmSTRING_DEFAULT_CHARSET);
  3678.         XmFileSelectionDoSearch (fileDialog, dirmask);
  3679.         XmStringFree (dirmask);
  3680.         if (lastSlash != NULL) {
  3681.           lastSlash [1] = '\0';
  3682.         }
  3683.       }
  3684.       XtFree (text);
  3685.       txt = XmFileSelectionBoxGetChild (fileDialog, XmDIALOG_TEXT);
  3686.       XmTextSetString (txt, str);
  3687.       XtVaSetValues (fileDialog, XmNmustMatch, TRUE, NULL);
  3688.       fileBoxUp = TRUE;
  3689.       fileBoxRsult = FALSE;
  3690.       XtManageChild (fileDialog);
  3691.       XSync (Nlm_currentXDisplay, FALSE);
  3692.       while (fileBoxUp) {
  3693.         Nlm_ProcessAnEvent ();
  3694.       }
  3695.       if (fileBoxRsult) {
  3696.         Nlm_StringNCpy (fileName, filePath, maxsize);
  3697.       }
  3698.       XtUnmanageChild (fileDialog);
  3699.       XSync (Nlm_currentXDisplay, FALSE);
  3700.     }
  3701.   }
  3702.   return fileBoxRsult;
  3703. #endif
  3704. }
  3705.  
  3706. #ifdef WIN_MSWIN
  3707. static void Nlm_CopyDefaultName (Nlm_CharPtr dst, Nlm_CharPtr src)
  3708.  
  3709. {
  3710.   Nlm_Char  ch;
  3711.   Nlm_Int2  i;
  3712.   Nlm_Int2  j;
  3713.   Nlm_Int2  k;
  3714.  
  3715.   if (dst != NULL && src != NULL) {
  3716.     i = 0;
  3717.     j = 0;
  3718.     k = 0;
  3719.     ch = src [i];
  3720.     while (k < 8 && ch != '\0' && IS_ALPHANUM (ch)) {
  3721.       dst [j] = ch;
  3722.       i++;
  3723.       j++;
  3724.       k++;
  3725.       ch = src [i];
  3726.     }
  3727.     while (ch != '\0' && ch != '.') {
  3728.       i++;
  3729.       ch = src [i];
  3730.     }
  3731.     if (ch == '.') {
  3732.       dst [j] = ch;
  3733.       i++;
  3734.       j++;
  3735.       ch = src [i];
  3736.       k = 0;
  3737.       while (k < 3 && ch != '\0' && IS_ALPHANUM (ch)) {
  3738.         dst [j] = ch;
  3739.         i++;
  3740.         j++;
  3741.         k++;
  3742.         ch = src [i];
  3743.       }
  3744.     }
  3745.     dst [j] = '\0';
  3746.   }
  3747. }
  3748. #endif
  3749.  
  3750. extern Nlm_Boolean Nlm_GetOutputFileName (Nlm_CharPtr fileName, Nlm_sizeT maxsize,
  3751.                                           Nlm_CharPtr dfault)
  3752.  
  3753. {
  3754. #ifdef WIN_MAC
  3755.   Nlm_Char       currentFileName [64];
  3756.   Nlm_Char       currentPath [256];
  3757.   unsigned char  original [256];
  3758.   unsigned char  promptStr [256];
  3759.   Nlm_PointTool  ptool;
  3760.   Nlm_RecT       r;
  3761.   SFReply        reply;
  3762.   Nlm_Boolean    rsult;
  3763.   Nlm_RectTool   rtool;
  3764.   GrafPtr        tempPort;
  3765.   PenState       state;
  3766.   Nlm_PoinT      where;
  3767.  
  3768.   where.x = 90;
  3769.   where.y = 100;
  3770.   GetPenState (&state);
  3771.   GetPort (&tempPort);
  3772.   Nlm_PoinTToPointTool (where, &ptool);
  3773.   original [0] = '\0';
  3774.   Nlm_StringNCpy ((Nlm_CharPtr) original, dfault, sizeof (original));
  3775.   Nlm_CtoPstr ((Nlm_CharPtr) original);
  3776.   Nlm_StringNCpy ((Nlm_CharPtr) promptStr, "Save File As:", sizeof (promptStr));
  3777.   Nlm_CtoPstr ((Nlm_CharPtr) promptStr);
  3778.   SFPutFile (ptool, promptStr, original, NULL, &reply);
  3779.   SetPort (tempPort);
  3780.   SetPenState (&state);
  3781.   Nlm_GetRect ((Nlm_GraphiC) Nlm_desktopWindow, &r);
  3782.   Nlm_RecTToRectTool (&r, &rtool);
  3783.   ClipRect (&rtool);
  3784.   if (reply.good != 0 && fileName != NULL) {
  3785.     Nlm_StringNCpy (currentFileName, (Nlm_CharPtr) &(reply.fName),
  3786.                     sizeof (currentFileName));
  3787.     Nlm_PtoCstr (currentFileName);
  3788.     Nlm_GetFilePath (reply.vRefNum, currentPath, sizeof (currentPath));
  3789.     Nlm_StringNCat (currentPath, currentFileName,
  3790.                     sizeof (currentPath) - Nlm_StringLen (currentPath));
  3791.     Nlm_StringNCpy (fileName, currentPath, maxsize);
  3792.     rsult = TRUE;
  3793.   } else {
  3794.     rsult = FALSE;
  3795.   }
  3796.   Nlm_Update ();
  3797.   return rsult;
  3798. #endif
  3799. #ifdef WIN_MSWIN
  3800.   FILE  *f;
  3801.   char  szDirName [256];
  3802.   char  szFile [256];
  3803.   char  szFileTitle [256];
  3804.   UINT  i;
  3805.   UINT  cbString;
  3806.   char  chReplace;
  3807.   char  szFilter [256];
  3808.   char  *lastSlash;
  3809.  
  3810.   GetModuleFileName (Nlm_currentHInst, szDirName, sizeof (szDirName));
  3811.   lastSlash = strrchr (szDirName, DIRDELIMCHR);
  3812.   if (lastSlash != NULL) {
  3813.     lastSlash [1] = '\0';
  3814.   }
  3815.   szFile [0] = '\0';
  3816.   Nlm_CopyDefaultName ((Nlm_CharPtr) szFile, dfault);
  3817.   Nlm_StringCpy (szFilter, "All Files (*.*)|*.*|");
  3818.   cbString = (UINT) Nlm_StringLen (szFilter);
  3819.   chReplace = szFilter [cbString - 1];
  3820.   for (i = 0; szFilter [i] != '\0'; i++) {
  3821.     if (szFilter [i] == chReplace) {
  3822.       szFilter [i] = '\0';
  3823.     }
  3824.   }
  3825.   memset (&ofn, 0, sizeof (OPENFILENAME));
  3826.   ofn.lStructSize = sizeof (OPENFILENAME);
  3827.   ofn.hwndOwner = Nlm_currentHWnd;
  3828.   ofn.lpstrFilter = szFilter;
  3829.   ofn.lpstrFile = szFile;
  3830.   ofn.nMaxFile = sizeof (szFile);
  3831.   ofn.lpstrFileTitle = szFileTitle;
  3832.   ofn.nMaxFileTitle = sizeof (szFileTitle);
  3833.   ofn.lpstrInitialDir = szDirName;
  3834.   /*
  3835.   ofn.Flags = OFN_SHOWHELP | OFN_OVERWRITEPROMPT;
  3836.   */
  3837.   /* OFN_OVERWRITEPROMPT causes crashes for some unknown reason */
  3838.   ofn.Flags = OFN_SHOWHELP;
  3839.   if (GetSaveFileName (&ofn) && fileName != NULL) {
  3840.     Nlm_StringNCpy (fileName, ofn.lpstrFile, maxsize);
  3841.     AnsiToOemBuff (fileName, fileName, maxsize);
  3842.     f = Nlm_FileOpen (fileName, "r");
  3843.     if (f != NULL) {
  3844.       Nlm_FileClose (f);
  3845.       if (Nlm_Message (MSG_YN, "Replace existing file?") == ANS_NO) {
  3846.         return FALSE;
  3847.       }
  3848.     }
  3849.     return TRUE;
  3850.   } else {
  3851.     return FALSE;
  3852.   }
  3853. #endif
  3854. #ifdef WIN_MOTIF
  3855.   char   *lastSlash;
  3856.   char    str [256];
  3857.   char    *text;
  3858.   Widget  txt;
  3859.  
  3860.   Nlm_CreateFileDialogShell ();
  3861.   if (Nlm_fileDialogShell != NULL && fileName != NULL) {
  3862.     if (fileDialog == NULL) {
  3863.       fileDialog = XmCreateFileSelectionDialog (Nlm_fileDialogShell,
  3864.                                                 (String) "file_selection", NULL, 0);
  3865.       XtAddCallback (fileDialog, XmNcancelCallback, Nlm_FileCancelCallback, NULL);
  3866.       XtAddCallback (fileDialog, XmNokCallback, Nlm_FileOkCallback, NULL);
  3867.       XtAddCallback (fileDialog, XmNnoMatchCallback, Nlm_FileNoMatchCallback, NULL);
  3868.       XtAddCallback (fileDialog, XmNmapCallback, Nlm_FileMapCallback, NULL);
  3869.       XtVaSetValues (fileDialog, XmNdefaultPosition, FALSE,
  3870.                      XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL, NULL);
  3871.     }
  3872.     if (fileDialog != NULL) {
  3873.       txt = XmFileSelectionBoxGetChild (fileDialog, XmDIALOG_FILTER_TEXT);
  3874.       text = XmTextGetString (txt);
  3875.       Nlm_StringNCpy (str, text, sizeof (str) - 1);
  3876.       lastSlash = Nlm_StringRChr (str, DIRDELIMCHR);
  3877.       if (lastSlash != NULL) {
  3878.         lastSlash [1] = '\0';
  3879.       }
  3880.       XtFree (text);
  3881.       if (dfault != NULL) {
  3882.         Nlm_StringNCat (str, dfault, sizeof (str) - Nlm_StringLen (str));
  3883.       }
  3884.       txt = XmFileSelectionBoxGetChild (fileDialog, XmDIALOG_TEXT);
  3885.       XmTextSetString (txt, str);
  3886.       XtVaSetValues (fileDialog, XmNmustMatch, FALSE, NULL);
  3887.       fileBoxUp = TRUE;
  3888.       fileBoxRsult = FALSE;
  3889.       XtManageChild (fileDialog);
  3890.       while (fileBoxUp) {
  3891.         Nlm_ProcessAnEvent ();
  3892.       }
  3893.       if (fileBoxRsult) {
  3894.         Nlm_StringNCpy (fileName, filePath, maxsize);
  3895.       }
  3896.       XtUnmanageChild (fileDialog);
  3897.     }
  3898.   }
  3899.   return fileBoxRsult;
  3900. #endif
  3901. }
  3902.  
  3903. extern Nlm_Boolean Nlm_LaunchApp (Nlm_CharPtr fileName)
  3904.  
  3905. {
  3906. #ifdef WIN_MAC
  3907.   OSErr                err;
  3908.   FSSpec               fsspec;
  3909.   long                 gval;
  3910.   LaunchParamBlockRec  myLaunchParams;
  3911.   unsigned char        pathname [256];
  3912.   Nlm_CharPtr          ptr;
  3913.   Nlm_Boolean          rsult;
  3914.  
  3915.   rsult = FALSE;
  3916.   if (Gestalt (gestaltSystemVersion, &gval) == noErr && (short) gval >= 7 * 256) {
  3917.     if (fileName != NULL && fileName [0] != '\0') {
  3918.       if (Nlm_StringChr (fileName, DIRDELIMCHR) != NULL) {
  3919.         Nlm_StringNCpy ((Nlm_CharPtr) pathname, fileName, sizeof (pathname));
  3920.       } else {
  3921.         Nlm_ProgramPath ((Nlm_CharPtr) pathname, sizeof (pathname));
  3922.         ptr = Nlm_StringRChr ((Nlm_CharPtr) pathname, DIRDELIMCHR);
  3923.         if (ptr != NULL) {
  3924.           *ptr = '\0';
  3925.         }
  3926.         Nlm_FileBuildPath ((Nlm_CharPtr) pathname, NULL, fileName);
  3927.       }
  3928.       Nlm_CtoPstr ((Nlm_CharPtr) pathname);
  3929.       err = FSMakeFSSpec (0, 0, pathname, &(fsspec));
  3930.       myLaunchParams.launchBlockID = extendedBlock;
  3931.       myLaunchParams.launchEPBLength = extendedBlockLen;
  3932.       myLaunchParams.launchFileFlags = 0;
  3933.       myLaunchParams.launchControlFlags = launchContinue + launchNoFileFlags;
  3934.       myLaunchParams.launchAppParameters = NULL;
  3935.       myLaunchParams.launchAppSpec = &fsspec;
  3936.       rsult = (Nlm_Boolean) (LaunchApplication (&myLaunchParams) == noErr);
  3937.     }
  3938.   }
  3939.   return rsult;
  3940. #endif
  3941. #ifdef WIN_MSWIN
  3942.   Nlm_Char     ch;
  3943.   Nlm_Int2     i;
  3944.   Nlm_Int2     j;
  3945.   Nlm_Int2     k;
  3946.   char         lpszCmdLine [256];
  3947.   Nlm_Boolean  rsult;
  3948.  
  3949.   rsult = FALSE;
  3950.   if (fileName != NULL && fileName [0] != '\0') {
  3951.     Nlm_StringNCpy ((Nlm_CharPtr) lpszCmdLine, fileName, sizeof (lpszCmdLine));
  3952.     i = 0;
  3953.     j = 0;
  3954.     k = 0;
  3955.     ch = fileName [j];
  3956.     while (i < 8 && ch != '\0') {
  3957.       if (ch == '_' || IS_ALPHANUM (ch)) {
  3958.         lpszCmdLine [k] = ch;
  3959.         j++;
  3960.         k++;
  3961.         ch = fileName [j];
  3962.       }
  3963.       i++;
  3964.     }
  3965.     while (ch != '\0' && ch != '.') {
  3966.       j++;
  3967.       ch = fileName [j];
  3968.     }
  3969.     if (ch == '.') {
  3970.       lpszCmdLine [k] = ch;
  3971.       j++;
  3972.       k++;
  3973.       ch = fileName [j];
  3974.       i = 0;
  3975.       while (i < 3 && ch != '\0') {
  3976.         if (ch == '_' || IS_ALPHANUM (ch)) {
  3977.           lpszCmdLine [k] = ch;
  3978.           j++;
  3979.           k++;
  3980.           ch = fileName [j];
  3981.         }
  3982.         i++;
  3983.       }
  3984.     }
  3985.     if (k > 0 && lpszCmdLine [k - 1] == '.') {
  3986.       lpszCmdLine [k - 1] = '\0';
  3987.     }
  3988.     lpszCmdLine [k] = '\0';
  3989.     rsult = (Nlm_Boolean) (WinExec (lpszCmdLine, SW_SHOW) >= 32);
  3990.   }
  3991.   return rsult;
  3992. #endif
  3993. #ifdef WIN_MOTIF
  3994.   Nlm_Boolean  rsult;
  3995.   int          status;
  3996.  
  3997.   rsult = FALSE;
  3998.   if (fileName != NULL && fileName [0] != '\0') {
  3999. #ifdef OS_UNIX
  4000.     status = (int) fork ();
  4001.     if (status == 0) {
  4002.       execl (fileName, fileName, (char *) 0);
  4003.       Nlm_Message (MSG_FATAL, "Application launch failed");
  4004.     } else if (status != -1) {
  4005.       rsult = TRUE;
  4006.     }
  4007. #endif
  4008. #ifdef OS_VMS
  4009.     status = execl (fileName, fileName, (char *) 0);
  4010.     if ( status == -1 ) {
  4011.       Nlm_Message (MSG_FATAL, "Application launch failed");
  4012.     } else {
  4013.       rsult = TRUE;
  4014.     }
  4015. #endif
  4016.   }
  4017.   return rsult;
  4018. #endif
  4019. }
  4020.  
  4021. /* ++dgg -- added by d.gilbert, dec'93, for use w/ DCLAP c++ library */
  4022.  
  4023. extern void Nlm_SetObject (Nlm_GraphiC a, Nlm_VoidPtr thisobject)
  4024. {
  4025.   Nlm_GraphicData  gdata;
  4026.   if (a != NULL) { /* dgg - removed test for thisobject != NULL -- need to set null */
  4027.     Nlm_GetGraphicData (a, &gdata);
  4028.     gdata.thisobject = thisobject;
  4029.     Nlm_SetGraphicData (a, &gdata);
  4030.   }
  4031. }
  4032.  
  4033. extern Nlm_VoidPtr Nlm_GetObject (Nlm_GraphiC a)
  4034. {
  4035.   Nlm_GraphicData  gdata;
  4036.   if (a != NULL) {
  4037.     Nlm_GetGraphicData (a, &gdata);
  4038.     return gdata.thisobject;
  4039.   } else {
  4040.     return NULL;
  4041.   }
  4042. }
  4043.  
  4044.